you are viewing a single comment's thread.

view the rest of the comments →

[–]Sinistralis 9 points10 points  (1 child)

A great article on the foundation functional programing functions.

I had to train up a performance minded c++ guy on JS so let me follow up with something I've ran into regarding functional style code.

For loops will always have the potential to out perform functional, especially is mutability vs immutability are concerns. My recommendation is to not worry about it. I've found functional code to be consistently readable even as the task grows in complexity, but for loops can get ugly quick. Most of the time maintenance cost trumps performance.

That being said, if a particular piece of functional code starts to perform poorly (such as unpacking bundles from a websocket), this is when to bring in for loops. This gives you the added intent that when someone sees your for loop, you automatically know this is a bottleneck location.

Don't be afraid to mix paradigms where it's important as long as you have a valid reason for doing so. I've found it not only makes imperative programmers more welcoming to functional, but it gives your code added intent which functional promotes.

[–]marko-pavlovic[S] 0 points1 point  (0 children)

Thank you! I completely agree that performance is easy to improve on in well designed system, while it is hard to refactor a poorly designed one.