Programmers Really Don't Like 'Reduce'

Anecdotally, Programmers Dislike "Reduce"

Drawing on years of code reviews, Evan Hahn observes that peers rarely object to map or filter but often flag reduce as hard to read. He offers theories—unfamiliarity, worse performance, less elegance in JavaScript, Python, and Swift—and notes that in Clojure, reduce never drew complaints. He usually swaps it out and moves on, but wonders if others see the same pattern.

In my blissful stint as a Clojure developer, I did not get this feedback.
  1. chubot

    Related to the point about worse performance, I'm pretty sure I was there when reduce was "banished" from Python 3 -- demoted to functools.reduce(), instead of the builtin reduce() in Python 2

    The story is that sometime in 2006 or 2007, Guido van Rossum was debugging why a web page in Google's internal code review tool (which he wrote) was taking 30+ seconds to render.

    This is basically a "production" incident, since thousands of Google engineers relied on the tool. Requests like this were probably tying up threads and exhausting thread pools, perhaps

    Eventually it was tracked down to a line wrapping algorithm written with reduce(). I don't think he wrote it -- it may have come in through a dependency. As many know, reduce() is basically:

    s1 + s2

    s1 + s2 + s3

    s1 + s2 + s3 + s4

    ...

    And that's O(n^2) when s_i are strings. And I think it showed up if you viewed a 5000+ line diff, or a 5000+ line file. (Newer programs like Github also suffer here)

    I believe, in Python at that time, += was already optimized to avoid this (just like essentially all JS VMs are). Or you can use the idiom of append() to list and join() after.

    But reduce() basically forces the inefficient implementation, and I'm sure this is still true in Python 3.

    ---

    So basically Guido spent a long time debugging a performance problem related to reduce(), and made the decision to eject it. I was his officemate at the time, so I recall this, but I wasn't involved directly

    Also, somebody […]

  2. snackbroken

    Map and Filter are nice because they let you reason locally about a single element in isolation. Reduce(Fold) forces you to reason globally about intermediate results. Reduce also forces you to conjure up a "zero" value of the relevant type, which isn't usually difficult but it does constitute some extra mental overhead.

  3. japgolly

    I assume the author is talking about `fold`, as in `[A] -> B -> ((B,A) -> B) -> B`, and not what I often think of as reduce as `[A] -> ((A,A) -> A) -> A`.

    `fold` is awesome and super useful. It's the easiest and most convenient way to turn a collection into a single value. Put me anecdotally in the opposite bucket.

More from this day

2026-09-16