Prefer duplication over the wrong abstraction (2016)(sandimetz.com)
497 points by rafaepta 19 hours ago | 318 comments
tl;dr: Sandi Metz argues that premature or incorrect abstractions are more costly than duplicated code, because subsequent developers tend to preserve the abstraction by piling on parameters and conditionals, eventually producing incomprehensible code. Her recommended fix is to fight the sunk cost fallacy: inline the abstraction back into each caller, strip out the unused branches, and let the resulting duplication reveal a better abstraction. The fastest way forward, when an abstraction is wrong, is backward.
HN Discussion:
  • ~Single source of truth must override duplication preference when divergence causes bugs
  • Agrees that under-engineered code is easier to work with than over-engineered code
  • Abstractions are actually underused and enable solving bigger problems
  • Personal experience confirms DRY-driven abstractions create unmaintainable messes requiring duplication to escape
  • ~Functional programming or alternative paradigms largely sidestep these abstraction problems