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.
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.
This video should have a million views and I'm only 5 mins into the video. This is by far the best JavaScript based video I've seen in a long, long time.
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
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.
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!
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.
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")
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.
@@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.
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?
@@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! 🤓
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
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.
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.
@@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.
@@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!
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).
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.
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.
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.
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.
This video should have a million views and I'm only 5 mins into the video. This is by far the best JavaScript based video I've seen in a long, long time.
Thanks a ton for the compliment! Excited to see what you think by then end of the video 🔥
@@JanHesters Excellent, excellent video. I had to watch it a few times. Subbed! Keep up the good work!
@@JanHesters I don't see a section on Monads. I was hoping that was covered. That's the only thing I'd mention.
@@makerKID5 Will be their own video some day! Thanks for the suggestion.
Duuude, this is such good content. Love the presentation! Quick and straight to the point! Great job!!! Will sub for more
Thank you for the kind words!
Anything specific you want to learn?
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
That's so kind! Thank you 🙏
That was a banger, dude! Keep it up-you’re gonna level up for sure! 🔥
Thanks for the kind words!
You are intense. In form and content.
And … was that a tank in the forest?
Of course that’s a tank, what the heck. 🤨
It's a metaphor for robust code and the `pipe` function haha
Thank you for the kind words! 🙏
Bro your videos are just top notch. Much love from france ♥
Thank you! Really appreciate it.
Did you learn something fun new?
This is the best Javascript Video I've ever seen. (And I've been coding in JS since 8 years). Big kudos!
Thank you for the kind words! 🙏
Great content thank you for sharing
You're welcome!
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.
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!
FP patterns are the best way to write class methods :D
I see what you did there lol
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.
Absolutely!
Basically:
Readability > Cleverness > Performance
as long as performance doesn't matter. As soon as it does, the order switches.
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")
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.
@@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.
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?
@@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! 🤓
Thanks for the explanation, left a like!
Thank you so much!
Functional Programming oof, thanks surely, am subscribing!
Thank you! 🙏
Just one question: where you in the movie Split by M. Night Shyamalan?
A few of me were, yes 😉
Now I want currywurst
Don't forget the Sauerkraut! 😄
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.
Sure!
If you want, you can drop your question here, or DM me on X: x.com/janhesters
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
Thank you!
What is unclear? Maybe I can help you after the fact! 🙏
@@JanHesters Maybe I just need to write a few examples and fail abit :D Thank you!
@@kaicooper9421 Let's go 🔥
Wait, I thought this was Aphex Twin music video ;)
Avril 14th - all day!
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.
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.
@@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.
@@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!
Is this video going to help me to learn React?
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).
@@JanHestersThank you.
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.
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.
This is sweet
Insane thumbnail
Thank you!🙏