本文由 AI 分析生成
建立時間: 2025-07-07
Summary
EN: Matthias Endler argues against reflexive DRY (Don’t Repeat Yourself) application, making the case that copy-pasting is often the right choice early in a codebase’s life. The right abstraction emerges only after you’ve seen the pattern repeated 2-3 times with enough variation to understand the true shape. Premature abstraction creates rigid, hard-to-remove scaffolding that amplifies bugs across all call sites. Copy-pasting isolates bugs to individual instances.
ZH: Matthias Endler 反對機械式套用 DRY 原則,主張在程式碼庫早期複製貼上往往是正確選擇。真正合適的抽象需要在看到 2-3 次重複模式後才能浮現;過早抽象會建立難以移除的僵化框架,並讓 bug 透過共用抽象層擴散到所有呼叫端,而複製貼上則將 bug 隔離在各自的實例中。
Key Points
- DRY critique: “Don’t Repeat Yourself” applied too early creates wrong abstractions that are expensive to undo
- The right abstraction reveals itself after 2-3 copies — the variation between copies shows what’s truly shared
- Copy-paste maintains momentum: don’t interrupt flow to design abstractions prematurely
- Bug isolation: a bug in copied code affects one call site; a bug in a shared abstraction affects all callers
- Wrong abstractions are harder to remove than duplication: they become part of the team’s mental model and API
- The rule: copy once is fine, copy twice is a hint, copy three times means you now understand the abstraction
Insights
- The bug propagation argument is decisive: a shared abstraction turns a localized mistake into a systemic one
- “Repeat Yourself” is deliberately provocative — the actual claim is “abstract late, not early”
- This is related to Sandi Metz’s “wrong abstraction” essay: the cost of the wrong abstraction is not zero, it’s negative
Connections
- Directly complements the DRY principle debates in software engineering — the tension between abstraction and flexibility is perennial
- Connects to the software professionalism article: both argue that reflexive rule-following without judgment leads to poor outcomes
- The “abstract after understanding” principle aligns with how good architecture emerges from real usage (cf. YAGNI — You Aren’t Gonna Need It)
Raw Excerpt
“Copy-paste once. Then copy-paste again. By the third time, you’ll understand the pattern well enough to see what’s truly shared and what just looks shared. That’s when you extract the abstraction — not a moment sooner. The wrong abstraction will haunt you longer than the duplication ever would.”