经验上来说,程序员并不喜欢“reduce”。
Anecdotally, programmers dislike "reduce"

原始链接: https://evanhahn.com/posts/2026-09-13-programmers-dislike-reduce/

程序员往往乐于使用 `map` 和 `filter` 这类函数,却对 `reduce` 持保留态度。在代码审查中,`reduce` 常因可读性差而受到诟病,作者不得不将其替换为更传统的替代方案以减少阻力。 作者针对这种抵触情绪提出了几种假设:`reduce` 的直观性较差、知名度较低、性能可能欠佳,且在 JavaScript、Python 或 Swift 等语言中常常显得笨拙——尽管它在 Clojure 等函数式语言中感觉更为自然。虽然作者承认这些观察可能带有主观色彩或受代码审查标准演变的影响,但仍邀请他人分享观点,探讨这种对 `reduce` 的偏见是否是一种普遍现象。

相关文章

原文
Anecdotally, programmers dislike "reduce"

In short: from my experience, people like map and filter, but not reduce.

I use functions like map and filter all the time. When I put that code up for review, my peers rarely complain. I get plenty of feedback about other decisions, but not about my use of map and filter.

I cannot say the same for reduce. Often, when I’ve submitted a patch with reduce inside, I get a comment like, “this part is hard to read.” And I see reduce way less than map, filter, some, and so on.

Anecdotally, I have come to believe that programmers don’t like reduce as much.

I don’t know why, but I have a few theories:

  • reduce is harder to read.
  • reduce is less familiar.
  • reduce can have worse performance compared to other options.
  • reduce is less elegant in languages I use, like JavaScript, Python, and Swift. In my blissful stint as a Clojure developer, I did not get this feedback.
  • I’m wrong, and I’m seeing a trend that’s not real.

I usually just change reduce to something else and move on. Even though I prefer it, I don’t usually care much. But it’s a little social phenomenon I’ve observed, and I thought I’d document it.

I’ve also noticed this less recently, possibly because code review is less thorough nowadays.

Do you notice this? Do you like reduce? Please tell me.

联系我们 contact @ memedata.com