The mystic term of Functional Programming (FP) must be familiar to any JS developer. The first impression when we say “JS supports functional programming paradigm”.
The mystic term of Functional Programming (FP) must be familiar to any JS developer. The first impression when we say “JS supports functional programming paradigm” or “JS is a Functional programming language”, could be, well I use functions in JS, so I’m already doing Functional programming. This is the myth that we’re going to bust together.
You might be using the FP unknowingly but there’s a lot more to the world of Functional programming which takes years of experience to master. It involves re-wiring your thinking process to observe and implement the FP patterns in your style of writing programs.
But before we go any further, we need to understand the basic pillars of FP and why is it worth learning FP in general.
Functional Programming (FP) is a programming paradigm or a way/style of programming which has the following characteristics:
It’s more of a way of adapting your brain to think of the FP patterns in your programs.
We’ll learn about all of this using practical examples in a moment.
Below are the convincing reasons to learn FP:
Consider this code snippet which gets the best products out of an array of products.
It does the job, it gives the correct output. But we had to read through the whole code like a story or a series of steps we’re telling the computer to execute in order to make meaning out of it. A computer is excellent at this job of executing programs step by step as a sequence of instructions. And above is a classical example of Procedural programming. So, even though the keyword “function” is used here, it doesn’t make it qualify for Functional Programming because it violates the fundamental principles of FP like pure functions and no side-effects.
Let’s see a declarative version of the above snippet.
Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.
Let’s talk about the raw way of writing functions. Functions perform certain set of actions according to our requirements which could include fetching data, updating State, changing a set of mutable values and updating the DOM and so on.
In the past few years, the buzz around functional programming has been growing, but it can be challenging to apply theoretical concepts to everyday work. How can we make the code we work on more functional? What advanced patterns can you use, and why should you do that? And what do React hooks have to do with all this? In this talk we’ll have a look at real-life examples and patterns you can use to make React apps more functional.
One of the core ideas in functional programming is composition: building larger things from smaller things. The canonical example of this idea should be familiar with legos.