
Lesson Description
The "Wrapping Up" Lesson is part of the full, Functional JavaScript First Steps, v2 course featured in this preview video. Here's what you'd learn in this lesson:
Anjana wraps up the course by asking students to share thoughts about functional-style programming. Additional resources are provided and students are encouraged to explore other functional languages.
Transcript from the "Wrapping Up" Lesson
[00:00:00]
>> Anjana Vakil: We have really burdened our brains with a lot of stuff. Sure, we might have been doing very simple little functions like push and pop and map and reduce, but are they so simple? No, we had a lot going on in there. We had, we talked about pure functions and how they are far and away the idea behind functional programming.
[00:00:21]
And we talked about the opposite of the idea, which is side effects and non deterministic, like depending on other stuff outside of the function. We talked about recursion as a way to execute the same chunk of code over and over and over again and to operate in series of data, like arrays.
[00:00:42]
For example, so that we can do the type of programming that we are used to doing with iterative loops and an imperative mindset. And we made some cool art with it and we also talked a lot about higher order functions. Functions that operate on other functions, they either take in other functions or they return other functions, or both and we implemented our good friends, map, reduce, filter.
[00:01:12]
We learned how we can use recursion for pretty much anything we want in functional programming. We also talked about, okay, if we don't have state, we don't have values changing over time. Or data that's mutating over time, how do we remember information that we need? Do we really need to have like, massive function signatures with like 80,000 variables that take in all of the data that we need to do a computation?
[00:01:38]
No, we can take advantage of closure and split up that data into like partial applications of functions. And we can take advantage of composition to then take those split up functions and pipeline data through them so that we get the transformations we want. And then finally, we talked about how dangerous mutation can be in terms of having the rug pulled out from under you and you think your data is one thing, but your co-worker just updated it to something else.
[00:02:13]
[LAUGH] Or worse yet, some magic in the library you're using just did [LAUGH]. We talked about how to avoid that, A, by making sure we avoid like the plague any methods and operations in JavaScript that are inherently mutating. And by asking ourselves, how we would live without them.
[00:02:36]
And, or by working with tools like immer or immutable JS, persistent data that not only helps us with efficient copies. But also in the case of immer, lets us pretend that we're pushing to an array when we're actually not messing with it. So we have covered a lot of ground together today.
[00:02:57]
I am very thankful to all of you for grappling with all these things, and I would love to know before we break. What you feel are some takeaways from our, [LAUGH] arguably very brain hardy [LAUGH] to use the technical term discussions today. Are there certain ideas we've talked about today that you feel like, okay, I don't know about all that other pipelines or whatever, but I could really apply this idea to my daily life as a programmer.
[00:03:37]
And think a little bit more functionally about my programs. Anybody have anything that they're gonna try to kind of bring to their programming this is subjective.
>> Speaker 2: I think it was very helpful to see the extent of what you have to do to utilize it in places where it needs state.
[00:03:56]
Cuz most of the time when I learned recursion, functional programming, like concepts, they were a lot more, mathematical. And just kind of, just having all your stay kind of in the top, most level somewhere where it's all followed and controlled is where you want to have it when you're actually implementing it in a higher order application.
[00:04:22]
>> Anjana Vakil: So sort of getting into that idea of pushing the impurities away, pushing the state to the outer edges, and making sure that all of the operations that we're doing are stateless. Even if we do need some state at some point, making sure that sandbox in a way where we can be certain the rest of our program is not infected by it like the zombie virus.
[00:04:46]
Awesome thank you for sharing.
>> Speaker 3: I'm still thinking about performance implications especially when it comes to recursion. And that was helpful, at least in my mind, to picture what's happening when you tied it to the call stack. And so now I'm wondering if other more functionally designed languages who are maybe not single threaded like JavaScript, if that would have a performance benefit?
[00:05:16]
>> Anjana Vakil: I mean, this is the thing there's a lot of optimizations that can be done on the language implementation level that we as the programmers who use the language don't usually think about every day. But that become very relevant once you start thinking about like super intense data applications.
[00:05:37]
And so, yes there are dedicated languages that are good for this. Or for example, immer is an example or any immutable data structure library for JavaScript is also a performance related tool that we can use clever implementations of a lot of things like arrays. Or what have you that handle a lot of that performance bottlenecks for us, and yes, highly encourage folks to go try out.
[00:06:10]
Or at least look at some other languages that are kind of more explicitly designed for functional programming. Rather than our good friend JavaScript that was born in a lab in 10 days, anyway [LAUGH]. And yeah, highly encourage you to go deeper again I'll leave you with a whole bunch of links that you can dig into.
[00:06:32]
I wanna give a huge thank you to all of you for dealing with these hoops that I've been making you jump through, not hoops [LAUGH]. And for asking these great questions and sharing these gotchas and, but what abouts and that is the work, right? We are doing the rubber meets the road work of actually trying to apply these ideas and not just sit back and watch some academic talk about category theory or whatever.
[00:07:04]
So amazing work and I also wanna give a big shout out. I would not be here teaching a workshop on functional programming had I not accidentally stumbled upon functional programming in a community. And again, I mentioned it earlier, it's called the recurse center. It's super cool so I'm not here to plug it, but please go check out the website.
[00:07:23]
And huge thank you to everyone that I met there that taught me all of these things and helped me bang my head against them. And I hope you all can now go be that person for your team or whatever. Really appreciate you all, stick in with it.
>> [APPLAUSE]
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops