Check out a free preview of the full JavaScript: From Fundamentals to Functional JS, v2 course:
The "Functional Programming" Lesson is part of the full, JavaScript: From Fundamentals to Functional JS, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Bianca introduces functional programming and how it compares to object-oriented programming. Brianca takes a question from a student about the tenets of functional programming.

Get Unlimited Access Now

Transcript from the "Functional Programming" Lesson

>> Bianca Gandolfo: So, I know this course isn't about functional programming, but I thought I should say a few words about it just because of the name of the course. So, functional programming is a programming style that is really hip right now, yeah? Do you guys know? It's the cool thing.

[00:00:15] It was very hip for a while, but it's becoming more and more hip, and I guess maybe before was more hipster and now it's becoming more hip right? It's integrated into more front and frame works and things like that and it's become an expectation that you can read functional style code and use functional utility methods in your code.

[00:00:40] And they come for free with JavaScript, right? You have a lot of array methods that are functional leaning. So what is functional programming about? It's about breaking up your code into verbs, really, right? They say functional programming is about verbs, object oriented programming is about the nouns, right?

[00:01:04] It's a lot easier for you to think about software in terms of objects just because, as humans, that's kind of where we live in the physical world, right? This is a podium, I have my laptop, right. We think in terms of nouns where as functional programming you're thinking in terms of the actions.

[00:01:27] So if we were going to build a house, in object oriented programming, we would talk about the walls, and doors, and the windows, and in functional programming, we talk about opening and closing and we would apply it to the material of the house. Or we would talk about, what is another action that you can do in a house?

[00:01:45] Turning something on or turning something off, so we're thinking and designing our software around these concepts. And so we use a lot of functions, hence the name functional programming. And we are passing functions to functions, returning functions from functions, doing things with the arguments and the parameters. Yeah, so it's a style.

[00:02:13] This is not about functional reactive programming. Functional reactive programming is a functional style with streams, observable streams. Have you guys seen, or heard of observable streams? So that's the other really cool thing these days. And I wish I had time to teach it, cuz it is really cool, but it is what it is.

>> Speaker 2: We had two courses on that.
>> Bianca Gandolfo: What's that?
>> Speaker 2: Observables.
>> Bianca Gandolfo: Good.
>> Speaker 2: So, we have asynchronous programming with JavaScript with Jaffer Hussein.
>> Bianca Gandolfo: Cool
>> Speaker 2: And that's a two-day course and then we also have an advanced one.
>> Bianca Gandolfo: Awesome, perfect, yeah
>> Speaker 2: So that's all about observables, and rx, and operators, and all that stuff.

>> Bianca Gandolfo: Yeah, so that's beyond the scope of this. Is it a two day course only on observable streams or just reactive in general?
>> Speaker 2: Well it's kind of mostly reactive programming, like taking a-
>> Bianca Gandolfo: Yeah, I guess it has to be.
>> Speaker 2: A data model, array, whatever.
>> Bianca Gandolfo: Yeah, okay.

>> Speaker 2: Converting it to observable and interacting with streams.
>> Bianca Gandolfo: Got it, cool. So we're not gonna be talking about rs, JS or anything like that. The things that we're gonna learn are gonna be more on the line of Lodash, Underscore, Ramda, things like that. Have you guys heard of any of these libraries?

[00:03:35] Who's heard of Underscore? Raise it high. Who's heard of Lodash? Awesome, who's heard of Ramda? Okay, so Ramda is a little more, so Lodash and Underscore are utility libraries that give you fun little functions that help you really transform data, and things like that, loop filter, etc. And Ramda is kind of a more hardcore version of that.

[00:04:04] So, we'll look more into it in a bit. We're not really gonna talk any more about functional programming as a style, so if you have any burning questions, now it's the time. I'm not a hardcore functional programmer, I only teach this class and this style because I've seen and I believe that it really helps you become a stronger programmer.

[00:04:25] So I don't have strong opinions about architecting in a functional style or some people-
>> Speaker 3: Could you just give some benefits that you see of functional programming as opposed to OOP?
>> Bianca Gandolfo: Yeah, sure. So, I think that one of of the core tenets of functional programming is making pure functions that don't have side effects and in doing that your code is a lot easier to test.

[00:04:53] And it's a lot easier to trust. And so that's a benefit over object oriented. However, the thing about functional programming is that if you're doing web, you have to have side effects, right? DOM manipulation, all this stuff, are side effects. A pure function as a input and an output.

[00:05:10] It can't do anything and effect any other data outside of the scope of that function, right? Which makes it easy to test and that's great but in the real world, especially in what we do, it's not always, you can't do a purely functional. And also some people get too crazy.

[00:05:27] I don't know if anyone has seen a very very hardcore functional programmer's code-base. Has anyone seen that? It can be really scary.
>> Speaker 2: Especially, yeah, when they're using bifunctor map. It's one thing to just use map, but it's like, okay, let's swap the arguments, plus-
>> Bianca Gandolfo: Yeah, it gets-

>> Speaker 2: Wrap it in a functor, and then all that's created, so.
>> Bianca Gandolfo: Yeah, it gets super crazy. We're not going there. And I don't think that that's even-
>> Speaker 2: Does it always sacrifice readability?
>> Bianca Gandolfo: No, it doesn't have to, it doesn't have to.
>> Speaker 2: Yeah, that's the whole thing around Cal Simpson's functional light course.

>> Bianca Gandolfo: Mm-hm.
>> Speaker 2: He has a course on there, which he's trying to bridge the gap between sort of the basic functional concepts and applicable, readable code. A functional can actually make your code more readable if you use it without going to the extremes of crazy monoid structures and all that stuff.

[00:06:27] But the basics of functional can clean up your code drastically, and make it way more readable.
>> Bianca Gandolfo: Yeah, and it can help you prevent errors and stuff as well, off by one errors with loops. And we'll talk a little bit about that, each, and map, and things like that will help you prevent those kinds of errors.

[00:06:49] But we're not gonna talk about monads, or monoids, or functors, or anything super academic. My style is we're gonna keep it practical, things that you actually need to know to understand the fundamentals. And then grow into something like the next functional programing course that you take. Whether it's Cal Simpson's one, which I think, it's not a big jump from this course, right?

>> Speaker 2: Yeah, I mean, he does get pretty deep. It's a deep course but it starts very basic.
>> Bianca Gandolfo: It's not as hard as Dr. Bullion's though.
>> Speaker 2: Yeah, yeah, if you go to Hardcore Functional Programming,
>> Bianca Gandolfo: Yeah, it's called Hardcore Functional Programming, so.
>> Speaker 2: Yeah, it's more like taking and turning JMA into JavaScript.

>> Bianca Gandolfo: Yeah, so we won't be getting into that, but if you're interested in that and you've tried it, and you're like, I have no idea, this is a good place to start.