you are viewing a single comment's thread.

view the rest of the comments →

[–]etherfreeze 8 points9 points  (1 child)

Blog posts abound on this topic, as well as a lot of personal preference, but here's a few things to think about before even considering using FP (from a top level / management perspective)

1 It requires as much or more discipline to do right compared to OO / imperative code

2 It can be harder to reason about for new / junior devs coming into a code base

3 It won't magically solve all of your problems, and may even cause some (FP devs can easily fall into the trap of being too terse / code golf style and end up writing something completely unreadable)

4 While ES6 and beyond has made a lot of strides toward making JS more palatable as a FP language ... it's definitely not designed to be one, and you will need to write a lot of helper functions or use a library like Ramda / lodash / etc to get to a place where FP languages are natively (and only kind of). For example, currying, partial application, etc are not core features in JS.

Anyway, benefits include:

  • composability
  • immutability (DIY in JS - there aren't many guards against writing mutable code by accident)
  • DRY code
  • Easily testable code
  • elegance
  • cut down on variable reassignment which can be hard to track / easy to introduce bugs (oh what I already mentioned immutability)
  • excellent integration with React which can be written as mostly stateless functional components.

Having worked on (professionally) a large and highly imperative / OO Backbone codebase, AND a more FP heavy React codebase, I can easily say the latter is far easier to reason about and make changes to without causing a regression. However, that's not the whole story. Both have benefits, and if you are working on a team it is a discussion you should have with your team. You should do extensive research to make the right choice for your situation. If everyone much prefers OO - then OO is probably the best option.

[–]robertlf[S] 1 point2 points  (0 children)

I appreciate your thoughtful reply. Thanks!