← Wed, Sep 16 digest

Anecdotally, programmers dislike "reduce"

read article ↗ hn thread ↗

summary

Many developers find the 'reduce' function difficult to read and less intuitive than 'map' or 'filter'. This dislike stems from its versatility, which often makes the code less explicit about its intent. Consequently, developers frequently request changes to avoid 'reduce' in favor of more specialized functions during code reviews.

key points

  1. The 'reduce' function is often perceived as harder to read and potentially less elegant in mainstream languages like JavaScript, Python, and Swift. This leads to frequent negative feedback during peer reviews compared to the use of 'map' and 'filter'.
  2. The preference for 'reduce' is less common in languages like Clojure, suggesting that language-specific culture and syntax play a role in the acceptance of the software development community.
  3. The author suggests that the author's observation is a core social phenomenon where the author's preference for 'reduce' often leads to the author's authorial choice to replace it with other methods for the sake of team consensus.

who should read it

Software developers who use functional programming patterns and team leads who conduct code reviews. It provides a perspective on how coding style and readability concerns influence technical decisions.

discussion positive

consensus

Commenters generally agree that the naming and argument order of functional primitives like map, filter, and reduce are inconsistent across programming languages, often leading to developer confusion. While map is widely accepted, reduce and fold are criticized for varying parameter orders and potential 'footguns' such as missing initial values. There is a broader agreement that these inconsistencies make functional idioms harder to remember and implement correctly across different ecosystems.

top insight

A detailed anecdote explains that Guido van Rossum removed reduce() from Python's built-ins to prevent O(n^2) performance pitfalls during string concatenation. This highlight underscores a fundamental tension in language design between providing flexible functional tools and preventing common performance traps that are difficult for compilers to optimize in dynamic languages.

Generated by an LLM from the article and thread. Check the sources before relying on it.