Question

I'm a developer with very strong oop background. And Recently I want to learn javascript coz I think it's the future. But I find myself very hard to understand the functional programming part of concepts in javascript. I searched around and I got this "Haskell" language a lot in the functional programming world. A lot of people are saying if you want to learn FP you should learn haskell.

It'll be highly appreciated if someone can provide some inputs or someone can share some experience.

Was it helpful?

Solution

I think there is no binary answer to your question. Honestly, you don't have to learn Haskell to understand functional programming. But learning Haskell will make you understand functional programming better in my opinion.

You could learn functional programming using JavaScript, but the fact that JavaScript is not purely functional and allows you to write easily imperative code, won't force you to write difficult algorithms in a functional way. So each time you have difficulty writing something in a functional way, you will probably abandon and switch to your old habit.

I will add moreover that JavaScript hides a bit its functional programming and does not naturally provide functions such as map, reduce, composition, filter and functional characteristics such as currification. By the way, you should take a look at Underscore, which is a library for JavaScript that brings a lot of functions such as map. You might also be interested in CoffeeScript which is "a little language that compiles into JavaScript". This language is basically JavaScript with a better syntax, and it brings out the functional side of JavaScript. Even if you don't want to use it, just looking at the overview part and seeing how CoffeeScript translates to JavaScript will make you understand better JavaScript.

If you have time to learn Haskell, and force you to program non trivial algorithms with it, then you will have a really good understanding of functional programming. Haskell is pure so will have no other choice to force you to express your algorithms in a functional way. Moreover, you will learn concepts such as Functor, Monad, Curryfication, Pattern Matching that you will not learn by just using JavaScript in a functional way. One will argue that you don't need to know those concepts to be a good programmer in JavaScript, but if you know them you will see programming under a new way and it will probably change the way you program in any language.

To conclude, I will say learning Haskell, is not something you have to do to be a good JavaScript programmer, but it will help you to be more "open-minded" and to have a better programming culture. Learning Haskell asks a lot of investment, and will take you a lot of time, but it's also a lot of fun. If you want to learn it, I recommend you the book Learn You a Haskell for Great Good!.

OTHER TIPS

No.

Here's a pretty basic introduction to the functional capabilities of javascript. It assumes no knowledge of functional programming.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top