I’ve just searched “reduce” on Unsplash and this was the first result, philosophical! Photo by Noah Buscher

Member-only story

In defense of reduce()

Reduce has been getting a lot of “hate” recently: let’s spread some love!

--

I’ve seen a lot of debate in the JavaScript community lately. It’s strange ’cause it never happens!

The dish of the week seems to be Array.prototype.reduce(). Is it useful? Is it worse than loops? Is it readable? This is a recurring topic which has been brought up multiple times in the past: it’s a never-ending story. Which should be enough to conclude that there’s no definite answer and you should use what you prefer. Which is not always the most performant solution, and sometimes not the most readable code for everyone. You can never be sure your code will be familiar to everyone: each of us have preferences.

I’ve read a lot of interesting comments honestly! Someone trolled, some took it [maybe too] personally, some gave interesting perspectives, some made useful considerations about performance and optimization. I thought that since I’m passionate about Functional Programming, it may be interesting to write something about the whole “reducer pattern” (in general) and why you should at least consider using it. And maybe some tips here and there. It’s just food for thought, no wars, just pointing out something that I feel some may have missed. We have more important problems right now on our planet, let’s have some fun with our job…

--

--

No responses yet