What is functional programming
Functional programming means using functions as building blocks to construct a process. Unlike OOP, functional programming is not an imperative paradigm but a declarative one, meaning it describes what the code has to accomplish, but not how.
Below are some of the key concepts from functional programming
Pure functions are simple, reusable blocks of code written as functions, that don’t have any side effects, meaning the output of a function is defined by its input.
They should not modify anything outside of the function and should be stateless, meaning whenever the function runs, it should behave like it was its first time running. This also has more benefits like reducing the number of bugs that exist when there is a shared state between functions.
Example of an impure function that modifies a variable outside of itself.
The main idea behind immutability is that when the data is created, it will never be mutated again. In functional programming, this is a key concept. It helps get rid of the rather complex bugs caused by mutating data over time. Libraries such as React and Redux, only provide a state which is not modifiable directly, instead, they make it possible to always create a new state instead.
Functional programming can be very useful whether you are building frontend web applications or any other type of app. So if you haven’t already, I hope you give it a try and check for yourself if it's easier writing functional code.
Are you interested in reading more about Frontend in general? Then make sure you follow us on Twitter to get the latest updates.