Why and What is Functional Programming?

Hey folks!

Today we will talk about functional paradigm or functional programming (FP). Functional paradigm is a different approach to work with software development which the majority of software engineers are accustomed. Probably you as the majority of developers are working or have worked with Imperative paradigm and / or Object Oriented (OO) paradigm. So Functional paradigm has some different ideas to solve the same problems which Imperative and Object Oriented solve too, and as everything has pros and cons to be evaluated.

In these last years I was using a little of functional approaches in my code as osmosis because it was making my code better and simpler than OO. In majority of the time I knew the implementation, but I didn’t know about the meaning of what I was using and the theoretical benefits. I mean that I could see the benefits in my code, but I did know what it really was. In other words it was just a perception. In this year I started to work in a project where we were using a lot of functional techniques together with OO, and working with very smart folks which know a lot about FP. It showed me how important to deepen my knowledge in FP.

I am studying FP not to work with it in system which use 100% FP approach, but to open my mind to new solution to old problems that I was solving in majority of time using OO approaches. As when we study another language or framework to see new ideas and solutions to problems which we are solving in our day by day, study a new paradigm has the same objective.


But what are the Functional Paradigm main ideas?

Is possible, to me, says that immutability, avoid side effects, recursion, and pure functions are the principal ideas of FP. They are the base to start to use and mainly understand FP. In my opinion understand this base is the most difficult. When we have just a superficial vision about that it is easy, but when we start to dive in the paradigm it show the complexity.

Why learn FP can be hard?

I can see two reasons for that. First of all, switch from OO to FP is not simple because the concepts that we have in our mind and we used in our professional life for long time are totally different. Second, and in my opinion the most important, the FP came from math and we, developers, when start to learn it hardly ever start with math. As Imperative programming came from Touring machine, the FP came from Lambda Calculus and in my opinion it is the first thing that we have to study to make this process smoother.

But, what are the benefits?

If learn FP is hard and we have to invest a lot of time and effort to do it, then we have to be rewarded. In my short experience of FP the rewards which I can see are: Simplest code, much more easier to apply Single Responsibility Principle (SRP); Short functions. Probably majority of our functions doesn’t have more than 5 lines; Understandability. With a simple code and short functions the code become really understandable. Don’t forget the majority of our time we are just reading code; Immutability and pure functions. Is not necessary to be worry if the variable value change or not, because we just don’t have variables. Pass a value to a function and have sure that the result is always the same become the code much more predictable;


We can add much more benefits from FP as parallelism, but for me the best one is to open mind to a new approach and improve ourself as solvers.

The best way to learn FP, in my opinion, is learn Lambda Calculus, understand the basic concepts, and after choose a language to dig in it.

If you are in this journey or thinking to start it let your commentary and have a great experience!

Written on December 1, 2016