Anecdotally, programmers dislike "reduce"

Anecdotally, programmers dislike “reduce”

轶事:程序员似乎不喜欢 “reduce”

In short: from my experience, people like map and filter, but not reduce. 简而言之:根据我的经验,人们喜欢 mapfilter,但并不喜欢 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. 我经常使用 mapfilter 这类函数。当我把这些代码提交审查时,同事们很少会有异议。我经常会收到关于其他决策的反馈,但唯独不会收到关于使用 mapfilter 的反馈。

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. 但对于 reduce,情况就不同了。通常,当我提交包含 reduce 的补丁时,总会收到类似“这部分代码很难读”的评论。而且,我看到 reduce 被使用的频率远低于 mapfiltersome 等函数。

Anecdotally, I have come to believe that programmers don’t like reduce as much. 根据我的观察,我开始相信程序员确实没那么喜欢 reduce

I don’t know why, but I have a few theories: 我不知道原因,但我有几个猜想:

  • reduce is harder to read.
  • reduce 更难阅读。
  • reduce is less familiar.
  • reduce 的熟悉度较低。
  • reduce can have worse performance compared to other options.
  • 与其他选项相比,reduce 的性能可能更差。
  • 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.
  • 在我使用的语言(如 JavaScript、Python 和 Swift)中,reduce 的表现不够优雅。但在我作为 Clojure 开发者的那段快乐时光里,我从未收到过这种反馈。

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. 我通常会直接把 reduce 改成其他写法然后继续工作。尽管我个人更喜欢它,但我通常不会太在意。但这确实是我观察到的一个小小的社会现象,我想把它记录下来。

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. 你注意到了吗?你喜欢 reduce 吗?请告诉我。