Why go functional in programming?
Functional programming is hot now. I used to wonder what difference does it really make in going functional while coding…after all, if we can make the logic and code run, it should execute the program in the same way. But, in the last few weeks, I really changed my mind and get why functional programming is so much more effective. Hence, I’d like to share my experience.
Recently, I was assigned a very simple interview question to write an implementation for. Basically, the program was supposed to write a function that would count words given a paragraph of strings.
Then quickly, after the interview, I started to think how I could have done this in a functional way and saved time and space. At that moment, it dawned on me how functional programming can really help. Below is the gist of how I did the same thing in functional style. The code is half the size and easy to read.
So, the benefits of functional programming that I found were:
- Succinct Code
- Easy to read
- Reusable functions
- Easy to manipulate data structures
So, if you haven’t jumped on the functional side of programming yet, I highly recommend to take a peek at it. It indeed takes you to a more functional world!