Great presentation! But please everyone, be mindful when you're working in a team. It'll be rare that others in your team have studied and understood fp as much as you did. "Real" senior developers understand the value of easy-to-read, easy-to-maintain code. Junior devs create simple code for everyone on the team. Mid-level devs create opinionated, seemingly "so efficient", "so elegant" code. Senior devs create simple code again. I'll always remember how everyone on a team hated that one guy who added Ramda to the codebase and now they all had to work with it after he left. He was clearly smart and knew what he was doing, but he wasn't mindful of the team or of anyone coming after him. If in doubt, don't be that one guy who adds Ramda.
@JanHestersАй бұрын
I totally agree! Code readability and maintainability should always be a top priority. It's a balancing act between writing efficient code and ensuring that everyone on the team can understand and maintain it long-term. 1.) Sometimes, you want to use the best patterns AND teach the people who don't know them those patterns. (Especially in a mentorship-culture.) 2.) In other cases, you want to reach for the best tool that everyone knows. ("When in Rome, do as the Romans do.") My mentor taught me both.
@abahiduh324621 сағат бұрын
This is the best JavaScript video I have ever watched and I have almost the best video of most of the well know tutors from udemy, LinkedIn,pluralsite, etc HMMM
@JanHesters7 сағат бұрын
That's so kind! Thank you 🙏
@sefatanam15 күн бұрын
That was a banger, dude! Keep it up-you’re gonna level up for sure! 🔥
@JanHesters14 күн бұрын
Thanks for the kind words!
@demarcorrАй бұрын
functional programming is the kind of programming i do at 3am after being awake for 20+ hours. jokes aside, FP is great but just like OOP, going too heavy and far into FP and you just end up in a different web of frankly painful complexity. I get the piping and composing and currying but man I can absolutely see how someone would be utterly lost looking at that, and its not fun to try and understand. FP and OOP compliment each other well, and I've personally found myself writing my "best" or at least "better" code by using FP and OOP together, but never going to far into one or the other. Def a good vid though very succinct, I would prob reco up to about 25:44 for most people
@JanHestersАй бұрын
Thank you for the kind words! And I agree, always choose the right tool for the job and take into account what your team knows! 👍
@-N0PE-Ай бұрын
This is the best Javascript Video I've ever seen. (And I've been coding in JS since 8 years). Big kudos!
@JanHestersАй бұрын
Thank you for the kind words! 🙏
@gland_duАй бұрын
Bro your videos are just top notch. Much love from france ♥
@JanHestersАй бұрын
Thank you! Really appreciate it. Did you learn something fun new?
@coolaj86Ай бұрын
But at what cost? Clear > Clever. (the video was well done, but I walked away more firmly in the camp of "we should never allow this in a shared codebase")
@JanHestersАй бұрын
I mostly agree! But I disagree in certain circumstances. If you cannot train the team for whatever reason, then "yes," you should go with the best solution that everyone understands. Or if functional programming would objectively be the worst solution, then also "yes," you shouldn't use these techniques. But, if you have a team with a culture of mentorship and functional programming is the best solution, you should definitely level the team up and implement the cleanest solution.
@coolaj86Ай бұрын
@@JanHesters Have you ever tried to level up a team? Just getting basic automatic formatting, linting, and PR reviews implemented for the code that's there already is an absolute war of attrition. Well... I guess those are all boring things. There's probably a bigger market for people trying some new cool thing and feeling special about how smart they've become than doing the essential and tedious work of figuring out why core functions of the application are failing, seemingly at random, and any tiny change to something that changes the timing of database calls creates cascading failures... Of course, a big problem in the code base I'm thinking of is that they did use so much fp - but in all the wrong ways - using reducers to filter and create new objects, using maps to iterate over and mutate objects... most people aren't disciplined enough to use any of it correctly. They would be better of just sticking to for loops rather than creating things that no one else (or even they themselves) can read. You know what would be a really useful video? How to reset VSCode to a default working state after years of use. So many people disable all of the linting and other code tools and then things that should "just work" don't - because they've been disabled. If you're working with really next-level, hyper-intelligent people of a similar mindset I imagine that fp could be really fun and not hinder productivity, but we're at a state in technology where it's too much to expect people to get a contact form to work reliably. The hello worlds are failing. We need the simple for loops so that people can read what they wrote themselves. Most people need fewer tools, that they know how to use correctly, not more tools that they don't understand the nuance of. When I was young and all of that was being added to JavaScript, I used to think all those things were so cool and even used some of it correctly. Now... htmx is starting to look better all the time.
@coolaj86Ай бұрын
What tools do you have for leveling up a team? How do you approach it? How do you get people interested in quality and correctness over coolness and "if it fits it ships"ness?
@JanHestersАй бұрын
@@coolaj86 > What tools do you have for levelling up a team? In my opinion, one-to-many and one-on-one mentorship is the most important tool for any dev team. > How do you approach it? Make sure that you have regular mentorship sessions with your team. Lead by example. > How do you get people interested in quality and correctness over coolness and "if it fits it ships"ness? Show them your arguments. If they agree, your arguments are good. If they disagree, that might be because you have a blind-spot. To answer all of these questions, might take its own proper video. I'll put in my backlog. Thanks for the idea! But I hope this somewhat answered your questions. If you have follow up questions, let me know. And if you disagree, I'd also be interested in your view! 🤓
@deatho0ne587Ай бұрын
Do not assume that JS GC is always fast and that the new array/object is minor time spent. When it comes to million+ those things matter in terms of speed. I am not saying you should avoid functional programming in most cases, just know your rough max cases when dealing with Map, Set, Array stuff, and functional programming.
@JanHestersАй бұрын
Absolutely! Basically: Readability > Cleverness > Performance as long as performance doesn't matter. As soon as it does, the order switches.
@Itaysid6 күн бұрын
Great content thank you for sharing
@JanHesters2 күн бұрын
You're welcome!
@nicolasfioreАй бұрын
Just one question: where you in the movie Split by M. Night Shyamalan?
@JanHestersАй бұрын
A few of me were, yes 😉
@szeredaiakosАй бұрын
FP patterns are the best way to write class methods :D
@JanHestersАй бұрын
I see what you did there lol
@cCubifyАй бұрын
Thanks for the explanation, left a like!
@JanHestersАй бұрын
Thank you so much!
@abdelhadiamhamdiАй бұрын
Thank you for your amazing content! I've found it incredibly helpful and was wondering if you could assist me with some topics related to arity.
@JanHestersАй бұрын
Sure! If you want, you can drop your question here, or DM me on X: x.com/janhesters
@privacyvalued4134Ай бұрын
0:13 Nope! Using the splat operator = automatic fail. Simply put, you don't understand how expensive that operator is and that it should only ever be used very sparingly. Go write a DSL from scratch in a real programming language and implement the splat operator as part of it to learn how wrong your first 15 seconds of this video is. Splat may be convenient but trash like that it is why my web browser is chugging 10GB RAM half of the time. The rest of your example is what I call "symbol soup." It's unreadable because it uses symbols instead of words. Good coding practices balance words and symbols in a pleasing, easy to read/understand experience.
@JanHestersАй бұрын
The examples in this video are NOT meant to be production code, but just to teach the concepts of FP. (I mention it at the end of the video.) But your comment is good advice, I hope more people read it!
@rakeshgadaveАй бұрын
Is this video going to help me to learn React?
@JanHestersАй бұрын
Implicitly yes, absolutely! A good understanding of the language helps you understand any JS framework better. And for React specifically, it can help you clean up your code in general. It'll also help you to understand higher-order components, selectors in Redux, and why thinks are rendering (closure).
@rakeshgadaveАй бұрын
@@JanHestersThank you.
@kaicooper9421Ай бұрын
I feel attacked the way he put 'senior' in quotes. Where can I go to get a better understanding, I was kinda lost towards the end. Great video, I learned a lot though
@JanHestersАй бұрын
Thank you! What is unclear? Maybe I can help you after the fact! 🙏
@kaicooper9421Ай бұрын
@@JanHesters Maybe I just need to write a few examples and fail abit :D Thank you!
@JanHestersАй бұрын
@@kaicooper9421 Let's go 🔥
@husseinkizz22 күн бұрын
Functional Programming oof, thanks surely, am subscribing!
@JanHesters19 күн бұрын
Thank you! 🙏
@CottidaeSEAАй бұрын
In your curry function you copy memory four times just for the sake of immutability, which is already guaranteed by just doing 1 + 1. You'll have awful performance and you're using it for a simple addition? At least use a good example. I also really do not agree that this code is any more or less testable than OOP code. The problem is always state and keeping it correct at all times. That is usually not due to any one function being incorrect, it is due to developers making simple logic mistakes. Most bugs I've found in production are impossible to find with unit testing, because that's not where the bug is. Most of all, I just think JavaScript is a candidate for FP due to performance reasons. You don't really have to do much in order to get JavaScript to absolutely chug and lock down the browser, and on the server there's just so many more performant options. Even Java is more performant, then there's Kotlin even in the JVM world which tends to be more performant. C#, C++, Rust, Go, all of them are more performant. That's for the languages not even specifically for FP.
@JanHestersАй бұрын
Absolutely agree. I said at the end of the video that the examples in this video are contrived and optimized to be understandable. I disagree that OOP coder is easier to test because by default class inheritance is the tightest form of coupling and frequently requires mocking. But if you have good examples for OOP code that is easier to test than pure functions, please kindly point me to it 🙏 And regarding performance, IMO you should favour readability over performance UNTIL performance becomes a bottleneck. I can't speak to those other languages you mentioned because I'm specialized in JavaScript.
@CottidaeSEAАй бұрын
@@JanHesters Easily testable OOP code honestly follows the same guidelines. Given the same input, you should get the same output. The thing that tends to get people thrown off is that with OOP and stateful classes, you'll have adjusted one of the inputs if you run the same method twice. In order to replicate the same thing you also need to replicate the class instance. Just with a really basic class (pure garbage I'd never write normally, so sorry about it being a bad example): class Addition { value; constructor(initial) { this.value = initial; } execute(value) { this.value += value; return this; } } assert(new Addition(2).execute(2).value, 4) would be 4, every single time you run it; same as FP. If you chain it like new Addition(2).execute(2).execute(2).value then you've fundamentally changed what it does, just like FP. Same principle, different execution. The class example is extremely stupid though, wouldn't write code like that normally, state is best stored in DB regardless. One of the benefits to using classes in JavaScript is that while it looks as if the objects all have their own methods, they are all only allocated once, which is a major benefit to anonymous functions added to objects which need to be allocated every time. This is not as important now with imports and exports being a thing, but look into how stupidly much memory is used in a regular application due to all of the object nonsense JavaScript injects since it needs to treat everything like a nondescript object. That's not the case in Java or C# for example, where they only keep the bare minimum to identify the class. As for why I think a lot about performance, it's because I work with larger datasets frequently, so I have to walk the tightropes of readability and performance a lot. This is true for both backend and frontend things; where updating/inserting 50k DOM elements is hell and takes ages even in a best case scenario, whereas remaking the entire HTML structure as a string and replacing all of it takes a few seconds. However, it only takes a few seconds under the assumption that I reuse memory through not allocating anything extra. This means reusing variables and pre-allocating memory as much as possible. I do enjoy FP though, I reach for it whenever possible, but only when I can afford doing so. I never do anything particularly crazy with it either, but the idea of passing functions to other functions is something I use regardless of FP or OOP. Command pattern is just that. The Addition class I gave as an example would be one of the classes one would pass to something that processes it. Somewhat unreadable, but with enough complexity in the business logic, it's totally worth it. Sorry about the long reply, not sure if you're going to read it either, but I hope my sleep-deprived brain didn't spew out too much nonsense.
@JanHestersАй бұрын
@@CottidaeSEA Thanks for the long reply! I for sure read it 🙏 Got it. As you said, the code you gave as an example is different from how you'd write it, but let me still address it because it demonstrates one of the problems I had with testing (and reading / understanding classes) as opposed to FP - even in production codebases with "real" code examples: You need to set up the internal state to run the different functions, and it's hard to understand a method in isolation. For example, if you had another method on that class, that would only do something if `value` was three, you'd need to either call `execute` three times, complicating the test. Or you'd need to manipulate the class directly, which then would obfuscate the test so it resembles the real usage less. With FP and pure functions, they usually map one input to an output, making it trivial to write tests for them and truly test them in isolation. And thank you for clarifying where you come from. Totally makes sense that you think about performance so much! 👍 I've been a fullstack dev for most of my career and over time I learned the best approach to browser performance is "fix it if it breaks, otherwise favor good DX (testability, readibility etc.)". (Most) Browsers are so fast nowadays that it doesn't matter if you take up extra memory. > I reach for it whenever possible, but only when I can afford doing so This pretty much sums it up! 😊 And in my experience, in most JS server and browser codebases, you don't need to optimize for performance so granularly. (Especially on the backend, if performance mattered, the teams switched to Rust or another fast language haha) Thanks again for your thoughtful reply!
@lookasinskyАй бұрын
I know that you wanted to show functional programming, but the example at the very beginning of the movie requires a lot of cognitive load so I would not say that we should write code like this. I've seen some projects where functional programming was in use and unfortunately I have to say that some parts of the project were too advanced in terms of the way how function currying was used. Thumbs up anyway.
@JanHestersАй бұрын
Thank you for your feedback! I agree and this is one of the last points of the video at the end 👍 Many of the examples are contrived to be as easy as possible. The goal of this video is to learn FP as opposed to real world use cases.
@petemoss3160Ай бұрын
Wait, I thought this was Aphex Twin music video ;)