Why Learn Functional Programming in JavaScript? (Composing Software)
Eric Elliott
4K32

I started following you, mainly because I didn’t agree entirely with the “class-less” thing after ES6 class was added. Long story short, I push hard for pure functional in Javascript as of today. However I think the reasons are important.

As you stated, Javascript is a multi-paradigm language, which in my opinion comes with one important downside, often overlooked (it has many upsides, but usually this downside is completely ignored): it doesn’t excel in any paradigm

This is important, think about it:

  • this is a problematic keyword in JS, in general with the fact that it can be changed, can cause a lot of headaches for Object Oriented
  • Missing immutability is painful because most library will pass you simple objects and you always have to convert to/from ImmutableJS or similar libraries (if you want immutability ensured) or you need a set of libraries to deal with objects without touching them (any recommendation?)
  • Every developer comes with its own ideas, so you must deal with multi-paradigm in your code as soon as you use any external libraries

These are just 3 points, but for me are the weakest sides of the multi-paradigm approach. I really hope the language will be updated to provide solutions.

That being said, I think the Object Oriented “side” of Javascript has much bigger issues than the functional one. Immutability is a nice-to-have feature, but you can work without it by having it as a convention. In the Object Oriented side, however, you might face the following problem:

  1. You don’t like this changing, or you are using => to bind your functions
  2. You decide to simply clone your object to use it for a different purpose
  3. The object is cloned with all its functions, except that those are bound to the old instance, with nasty consequences

Now it’s obviously something you can work around with a proper Clone service, but again, why do I have to face all this pain when I can just use functions on objects?

So yes, stick to functional paradigm, it has removed all the nasty things and all the gimmicks I had to learn while using Javascript, making it quite clean.

It’s not perfect, but when you work with immutable data, ES6 modules, raw objects (like if they are hashmaps), it starts to feel pleasant.

That being said, until immutability is brought in Javascript I’ll keep using it frontend only, there is a lot of choice on the backend and in my humble opinion, I found other functional languages which are currently more pleasant to work with syntax-wise and feature wise: my happiness comes first!

Like what you read? Give Francesco Belladonna a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.