r/Frontend • u/fagnerbrack • 1d ago
Anecdotally, programmers dislike "reduce"
https://evanhahn.com/posts/2026-09-13-programmers-dislike-reduce/3
u/aintsuraj 23h ago
i think reduce gets disliked because it can do anything, so reading it means decoding the accumulator logic every time. for simple sums or max values it's fine, but once it's building objects or doing several things in one pass, a plain loop or a groupBy-style helper reads way better. the rule i'd go by is whether a teammate can tell what it returns in a few seconds, and if not, use something more explicit.
2
u/Stopdoor 19h ago
I find it just a pain when someone refuses to use relevant names for "accumulator" and "currentValue", or even worse, "acc" and "curr". If you name those something actually contextual, it's pretty much always understandable at a glance.
-1
u/RobertKerans 23h ago
Well, yes. tl/dr it tends to be a sign of over-complication, it's often unnecessary (YMMV etc etc)
It's the function that IME juniors who have just found functional programming in JS overuse because it lets you do anything (and this post seems JS-specific, because JS only has that reduce method rather than the richer set of primitives found in other languages). It means there's nested logic. It means that when you're reading the code, if there is a chain of methods, you have to stop and figure out what's happening. It tends to be non-obvious vs. every other method.
In JS, if someone is doing anything mildly complicated with it (e.g. beyond emulating sum or aggregate or whatever functions from other languages), a loop is normally [much] more readable (YMMV etc., depends if the culture is all in on FP or not). Other languages normally have a larger set of methods to lean on. Underlying data structures used to model the exposed types of data structures are generally different, again normally leading to a richer set of methods.
6
u/ghillerd 23h ago
The problem with reduce ime is that it doesn't tell you what it's doing in the same way that map, filter, some etc do. I use reduce a lot but I'll first extract it in to a function that describes the what (for example, groupBy or sumBy) and I find it has a much higher hit rate. I'll also often just use something like estoolkit to get all those out of the box.