Why functional programming anyways?
These days we hear a lot of map, filter, inmutable values, functional components, reactive, and other (nowadays more familiar) concepts. So let’s bring some basics about these topics to the table.
Some history #
Comes from two big topics, Lambda Calculus and Category Theory.
Alonzo Church was the mathematician that introduced the concept of Lambda Calculus as a way of expressing a computation based on functions (in those days when people were still defining what a computation was). This is considered the first functional programming language, considering in those days there was no computer to program.
On the other hand, we have Category Theory, introduced by Saunders Mac Lane and Samuel Eilenberg. They were discussing a book topic and both came to the same conclusion, one using algebra and the other using topology, and based on that discovery they created a new subject.
These mathematicians worked on those ideas around 1930-1940 and then functional programming languages started to appear, Lisp, Iswim, and many others until 1990 when one of the most famous pure functional programming languages (and still used) was created, Haskell. After Haskell other languages have follow a similar path but not as pure as Haskell because some developers are not used to the concepts and syntax of the language. One attempt to create a pretty interesting (weird for some) language trying to find a balance is Scala, which has both sides, functional programming style + object oriented programming.
How are we using those concepts now? #
After years of development of multiple languages, some of them became very popular, like c++ for example, but based on its nature there was pretty difficult for some specific tasks like multi threading programming and that’s where functional programming languages shine because of their nature, inmutability (avoiding the mutation of values stored). So the benefits of using inmutable values in a multi thread environment was a success because there was no race conditions anymore since there was no competing write access to the same variable.
Also, the abstractions of some algorithms were more than useful for programs to become more readable, and easier to understand, that’s where we see map, filter, reduce and many other functions that are now incorporated in languages that are not purely functional.
Nowadays we see functional programming incorporated on almost every language and we see well known developers like Robert C. Martin, aka Uncle Bob write books about the topic using headlines like “Cleaner Code”.
Why should I care? #
As a developer, we are always looking for ways on how to improve our skills, and functional programming is one of many ways to do that. I can tell by my own experience that as soon as you discover the benefits of writing declarative software you will try to use it everywhere because the benefits will popup by theirselved.