The Hard Parts of Functional JavaScript

Functional Programming Benefits & Concepts

Will Sentance

Will Sentance

The Hard Parts of Functional JavaScript

Check out a free preview of the full The Hard Parts of Functional JavaScript course

The "Functional Programming Benefits & Concepts" Lesson is part of the full, The Hard Parts of Functional JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Will briefly explains the different concepts of functional programming that will be explored in depth during the course. The advantages of functional programming are also discussed.


Transcript from the "Functional Programming Benefits & Concepts" Lesson

>> Will Sentance: But take a look at this. We can produce a beautiful to do list of our code. Here it is. Here in our quiz game, we've taken in an object here with the name Will and score three and we grabbed the player's name. We then take their first name.

We're then gonna properCase it. We're then gonna prepend a label saying this is a user. We're then gonna create a dom element or a an element ready with that data in it. And we can then take that and render it to the web page. And people, look at the beauty of this.

Look at this beautiful readable style of code. No mysteries here what our code is actually doing. But to do so is gonna require us to wrangle our code out of the mini baby blocks of code, our little mini functions in some pretty interesting ways. It's gonna require us to rejoin those lines of code up into full size tasks.

We see a preview of it here. We're gonna make sure that those little blocks of code are really reusable. Once you break the task down to little baby steps, you can actually reuse those steps all over the place. But if you're gonna be reusing them all over the place, you probably wanna make sure they're independent of anything around them.

And that's exactly what we're gonna have to do today. We're gonna start off with higher order functions, and function composition. As I said, all those little atoms of code can be reused all over the place. How we combine them up is gonna depend on higher order functions and function composition.

Most of those tasks, things like implementing a number, looping through an array, they're typical tasks. We can couple them up again. Use them again. Write them once, keep it dry, don't repeat yourself. Use them again.
>> Will Sentance: As I say, if we're not going to be using that functionality once in one place, but all over the place, well, we better hope that they're independent and not relying on bits of data outside of them.

We're gonna need to understand purity of functions and state immutability. And if we're gonna be coupling up code and have those perhaps be running one after another, not controlled by us but controlled by some other functions, we may need to do some pretty interesting things that adjust our existing saved functions.

Maybe give them extra powers. Function decoration with the help of closure and partial application with the help of closure are gonna be our main techniques. But if we can do it, we're gonna end up with code that is more readable. Every single line, so beautiful. I know exactly what it's doing, easy to debug.

Every single line nicely labeled, and an individual unit whose only consequence is gonna be on the next slide, not the rest of the application. No mysteries of what each line does and the risk of it damaging the rest of our app. And easy to add features. We take these little baby functions, these little baby units, we combine them all back up.

We don't have to rewrite the components. We're just drawing up pre-written components. And that's exactly what we're gonna see today. It's gonna allow us to build out applications where functions are reusable, versatile, flexible little portions of code, independent, self contained and predictable steps, passing data from one to the next to the next to the next.

But it all starts with us being confident with the core principles of JavaScript.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now