5 Reasons Why Functional Programming Will Make You A Better Developer
In the last 3 years, Functional Programming has been on the rise, with influences promoting this philosophy through immutability and the use of pure functions coming from the React world. In the last year, I've switched to functional programming, and by doing so, I have doubled my income and evolved as a programmer. I'm going to break down what makes Functional Programming useful and something you want to try on your next project.
1 It encourages thinking ahead of the problem :
Using functional programming, you are encouraged to sit back and think more about what you will write. It is a style of programming that has some strict rules, and you need to think ahead to adhere to these rules. As developers often want to "dive in" to coding, thinking ahead is good if you want to save significant amounts of time in the future.
2 It is more expressive:
In the beginning, it might look like functional programming is harder to read, but once you get accustomed to it, you will find that you can say more through less code. The less code you have, the easier it is for other people to pick it up than OOP-style codebases, where the code tends to be very verbose. Verbose does not mean expresive.
3 It promotes the use of pure functions:
Pure functions use only their parameters to compute an output without any exterior effects. They are easier to understand, require no outside context, and don't modify the exterior world.
function sum(x, y) {
return x + y
} // pure function
function req(data) {
doRequest(data)
} // impure function
You can see that the first function is self-explanatory and does not influence other parts of the application. The second function also requires us to understand doRequest and its influences on the outside world.
4 It moves side-effects to the edge of programs:
Side-effects mean everything that modifies the world. They can be:
-
HTTP Requests
-
DB transactions
-
DOM manipulations
They are not bad things, quite the contrary. However, they tend to cause most errors inside our applications. Putting them at the edge means they should not be the focus in your application. Side-effects should be the last operation in your chain as this will help you debug faster.
5 It promotes immutability by default:
Immutability in programming means that the programmer cannot change a value directly, only through making a clone of that value. This principle is at the base of many State Management frameworks like Redux.
Immutability is helpful because it assures the programmer that the data they are working with at the given time will stay the same. Any other place in the application that wants to modify that value will make a clone. Immutability is VERY useful in the context of parallel programming.
Functional Programming is on the rise, and you should give languages like Elixir
, Clojure
, or Elm
a try.
I wish you well on your journey and hope I have made you curious about functional programming. You will become a better programmer by studying it.