Functional programming: the next big thing?

I don't have a good track record with predicting the popularity of end user technologies. I thought Google Wave would take over all other methods of communication. I later expected Google Glass to become popular and push the development of augmented reality products to a new level. Neither of those worked out, as we now know.

I seem to have done better with programming languages and frameworks, however. I picked up HTML and JavaScript in 1998-1999, followed by PHP in 2000-2001, and C++ for desktop applications around the same time. I started using Ruby around 2005, and later picked up Rails in 2008. I learned CoffeeScript and began using it in my projects in 2010, back when it was at 0.6.

All of these languages/frameworks turned out to have enduring popularity and have served me well. However, I'm always looking for the next level of productivity and expressiveness, and I have become somewhat dissatisfied with what I can get now.

I noticed that functional programming is becoming more popular across different languages and domains. So this is what I decided to explore next. I hope that my intuition is correct again, and that FP will become truly mainstream rather than being just another fad.

Here are some interesting discussions about functional programming:

Why functional programming?

So why functional programming and not something else? Here are my main reasons:

  • It offers a different perspective on programming; as I started writing my first programs in Haskell, I was often stumped, which hasn't happened for a while; I take it as an encouraging sign that I'm learning something truly new to me rather than just another variation of the familiar themes.
  • It's easier to parallelise functional programs, and I believe that parallel execution is really an inevitable requirement (see http://www.gotw.ca/publications/concurrency-ddj.htm for a decade old discussion of this).
  • Performance of the same order of magnitude as C++ - typically a lot faster than dynamically typed languages, but hopefully with the same level of terseness and expressiveness.
  • Built on a small set of composable concepts (functions and data types).
  • An almost implicit focus on higher order abstractions (FP seems to invite the creation of higher order functions).
  • Rising popularity of FP - there's got to be a reason why all kinds of languages are acquiring FP features (C++, C#, Java), new languages have them baked in from the start (Swift, Rust), and languages like Scala, F#, Clojure and Haskell are becoming more visible.

I've been keeping an eye on different FP languages (mainly Haskell, Scala, OCaml, F#, Clojure and Erlang) and Haskell seems to be the most intriguing so far.

Why Haskell?

These are the main reasons why Haskell seems to have the edge over other languages in my estimation:

  • It has been around for 25 years
  • Compact core language
  • Takes purity very seriously
  • Advanced type system with sophisticated type inference
  • Lazy evaluation
  • Very concise syntax
  • Currying is a core concept in the language
  • The ecosystem is maturing, e.g. package management now looks to be on par with Ruby and Python
  • Tantalising connections to mathematics (e.g. category theory).

As of now, I don't know if it's worth learning Haskell as a practical language though. There are some products implemented in Haskell, but I think there is a danger that people are attracted to it as a way of solving very difficult puzzles rather than because it provides significant productivity or quality gains. I've seen it happen a lot in the C++ world (particularly with C++ template metaprogramming).

I don't know enough to discern the real reason, but on the plus side, I've seen people express the sentiment that learning functional programming improves their coding style in "regular" languages. I'm interested in translating what I learn from Haskell back into CoffeeScript and JavaScript.

Why JavaScript/CoffeeScript?

I primarily develop web applications, but at this point, Haskell doesn't seem particularly viable for client side code in web applications.

JavaScript/CoffeeScript have first class functions. I've already been using Underscore.js and found it very useful. I've seen interesting libraries for functional reactive programming pop up (Bacon.js, Kefir.js and RxJS).

I'm interested to see to what extent functional programming can be applied in these languages.