DEV Community

Discussion on: Is functional programming in JS really worth it?

Collapse
 
stereobooster profile image
stereobooster

Several points:

I wouldn't even know how I could justify writing code like this to my team members.

Code should be readable by the team. Think of how much time you spend learning FP concept. The same amount of time would need to spend each team member...

You can learn and practice FP (in personal projects), but I would not put it in shared code base unless the whole team is on board.

Second: it depends how you define FP, but if we would define FP as the style programming which avoids mutations and side effects. You would see that curried functions and combination is not a goal by itself it's just a tool to achieve the goal. So you can use them or not as long the main goal achieved.

Third: JS doesn't have good support for FP. It has some bits, which would make your code look like FP, but not always give you the benefit of FP.

There are a lot of built in functions, which will mutate objects, for example RegExp.prototype.exec() or Array.prototype.splice(). There are no immutable data structures, so you would need to use something like immer to take care of that (or use copy with spreds).

What comes at no cost in FP languages, like auto currying or combination, you would need to implement or use library for it, like, rambda.

You can as well try to learn FP in a language which was designed for it, for example, Elm.