AstroKobi
Space · Astronomy · Wonder
engineeringSunday, June 21, 2026·3 min read

Prefer Duplication Over Wrong Abstraction

Duplication is far cheaper than wrong abstraction

A captivating abstract image featuring a blend of woven textures with soft, muted colors.
Photo: Robert Clark

The concept of preferring duplication over the wrong abstraction has been a topic of discussion in the software development community. This idea suggests that duplicating code can be more beneficial than creating an abstraction that does not fully fit the requirements. The wrong abstraction can lead to complicated and incomprehensible code, making it harder to maintain and modify. Sandi Metz's talk at RailsConf 2014 emphasized the importance of avoiding the wrong abstraction, stating that duplication is far cheaper than the wrong abstraction. This idea has been supported by various developers, who have shared their experiences with the consequences of wrong abstractions.

What happened

The problem of wrong abstractions arises when developers try to extract duplication from code and create a new abstraction. This abstraction may seem perfect at first, but as new requirements emerge, it becomes necessary to modify the abstraction to accommodate these changes. The abstraction becomes increasingly complex, leading to code that is difficult to understand and maintain. The pressure to preserve existing code and avoid wasting effort can lead developers to retain the wrong abstraction, even when it no longer serves its purpose. This can result in a codebase that is hard to comprehend and modify. The concept of preferring duplication over the wrong abstraction is not about avoiding abstraction altogether but about creating abstractions that are meaningful and effective.

Why it matters

The wrong abstraction can have significant consequences, including making code harder to maintain and modify. It can also lead to a codebase that is inflexible and resistant to change. On the other hand, duplicating code can make it easier to modify and maintain, as each piece of code can be changed independently without affecting other parts of the system. The idea of preferring duplication over the wrong abstraction is not about being lazy or avoiding abstraction; it is about creating code that is maintainable, flexible, and easy to understand.

+ Pros
  • Improves code maintainability
  • Reduces complexity
  • Enhances flexibility
Cons
  • May lead to code duplication
  • Requires careful consideration of abstractions
  • Can be challenging to determine the right level of abstraction

How to think about it

When considering abstraction, it is essential to think about the logic behind it and whether it truly represents the requirements of the system. Abstractions should be created when they are meaningful and effective, not just for the sake of avoiding duplication. Developers should strive to create abstractions that are easy to understand and modify, and that do not introduce unnecessary complexity. This requires careful consideration of the trade-offs between duplication and abstraction.

FAQ

What is the wrong abstraction?+
The wrong abstraction refers to an abstraction that does not fully fit the requirements of the system, leading to complicated and incomprehensible code.
Why is duplication preferred over the wrong abstraction?+
Duplication is preferred because it can make code easier to maintain and modify, whereas the wrong abstraction can lead to a codebase that is inflexible and resistant to change.
How can I determine the right level of abstraction?+
The right level of abstraction can be determined by carefully considering the requirements of the system and creating abstractions that are meaningful and effective.
Sources
  1. 01Prefer duplication over the wrong abstraction (2016)
  2. 02The Wrong Abstraction — Sandi Metz
  3. 03Prefer duplication over the wrong abstraction | Hacker News
  4. 04prefer duplication over the wrong abstraction
  5. 05Prefer duplication over the wrong abstraction - José Coelho
Keep reading