Transcript from the "Introduction" Lesson
>> Will Sentance: Hello. Welcome. I'm Will Sentance. I run Codesmith, a coding school online, in Los Angeles and in New York City. And today I'm gonna be talking to you about functional programming, an ever increasingly popular paradigm for structuring our complex code. We're gonna go under the hood of some of the fundamentals of functional programming.
[00:00:27] To give you the ability to take these techniques, apply them in ways in your professional code and combine them up with the other techniques you use to write more clean, more readable and more debuggable code bases. Here we go. Supposed we have a quiz application. We have users saved in it, we have the users data saved in it, their scores, their names, their link, etc., we have quiz questions saved.
[00:01:02] And then we run functionality on that saved data. For example, increasing your users score, pretending to a user's name, a term indicating they are a user, upper cases, a user's name, proper case all these tasks we wanna do on our data. That sounds fine, except when we building a full application.
[00:01:27] We have thousands and thousands of lines all changing that data. This line changes the data this, and that data is a very Available to all our other lines of code. Any change I make is high risk to affect the rest of my code base my list of instructions to my computer.
[00:01:46] This is untenable, certainly at scale. What is the answer? Well, the answer is always been functions. Functions allow us to compartmentalize our code, take the 10 lines of code that do one task and say, these 10 lines within them, they can only affect each other, and actually create a little mini store of data just for inside that function.
[00:02:12] So that when you run that code, you know that it's only consequence hopefully is gonna be other lines within that function. But here's the problem with that, even with a ten-line function, those instructions are pretty complex. In terms of the consequence they can have within ten lines, certainly with a professional style of writing code.
[00:02:32] And they're still written in the style to instruct the computer. So, it is imperative start is that how computer you're gonna do this? Not the declarative style. The nice human readable human style of do this English or the language style of do this, do this, do this. And by the way, when we run a function.
[00:02:52] We're still at risk of affecting our global store of data, that is all the rest of our code via what's known as global variables. To the point that functions as we know them, may well not be enough for a scalable code base. Imagine, If we could structure our code into individual units that are small enough that each of them every single line is self contained.
[00:03:24] As imagine that individual lines only thing that affects it would be stated right on that line as an input. And the only consequence of it will be stated right on that line as well as an output. And each of those lines will get a nice, human readable label such that when we use them, we'd know exactly what they're doing.
[00:03:49] If we could do that, it would transform how we write code. But how, how do we do that? It's functional programming. We're gonna build up our application from little tiny functions, little baby functions. But only do one or two small tasks, within and give those little baby functions nice names that declare to the reader what those functions do, within to ensure this little tiny functions have no consequences except on that line.
[00:04:41] We're instead going to have to couple of these lines of code each saved as little baby tiny functions back up into larger tasks.