If you had been in OOPs for as long as you can remember, jumping into functional programming (FP) can be tiring and if you had chosen haskell, at times it would be disappointing. After a while with Haskell, you will never want to go anywhere else and you will feel sick with all other languages!. I spent 5 years with enterprise scale C++ code base then jumped into Haskell. I mentioned ‘enterprise’ OOPs, means, it is either legacy code or a huge codebase with leaky abstractions everywhere.
My learning curve could be summarized as follows:
- Unlearn traditional encapsulation, class members etc., from OOPs; Learn to appreciate concise code and small variable scopes in FP
- Work with types, function signatures, type classes etc., rather than classes
- Pattern matching and equational reasoning.. a humble assignment operator from OOPs has a completely different meaning in Haskell!
- Most stuff can be solved by recursing and accumulating.. infact, a recursive code is more easy to write and read when compared to iterative code.
- Abstract away iterations and conditional reasoning as much as possible, solve things by function composition and currying
- ‘Functions as first class citizens’ helps to find neat way to do things. Importantly, arranging function parameters to support better currying is super fun
- Lazy evaluations.. I hit this wall very hard only after I started working with disk IO.
- Type errors and ‘could not deduce’ errors. There were times, when I wrote only couple of lines of code, but ended up fixing type errors all day. There are also days when I would expect a particular type error, but instead spend time to fix all the other unexpected type errors. All said, it always feels good to fix compilation errors rather than firing up GDB on a C++ core dump! a SEGV fault in Haskell application is very very rare.
- Everything works in first shot! and no core dump! .. almost always this will happen and many a times, you would never think about writing unit tests. Compilation itself is a very important happy path unit test 🙂
- My code is getting cleaner as I learn more of Haskell! .. this will keep on happening. No matter how much ever you discover, there are always more ways to abstract things. Since code refactoring is very cheap, you will never think twice to refactor that age old code and make it more concise.
- Coming across weird blog posts, papers, talks by Haskell theory gurus.. This one should not scare you. With time, you will know what to look for and what all to skip to get your work done fast. It is fun to solve real world problems by stealing ideas and implementations done by these gurus.
Did I mention, I am not very interested in Math? People always feel, you should be a Math guru to use advanced haskell features. Yes, being a Math guru helps you pick up things quite easily. But you can survive and do better in Haskell even with lesser interest in Math
Now I am dirtying my hands with Erlang; with each passing day I feel terrible to miss the wonderful static type system of Haskell.