DRY

Also known as: Don't Repeat Yourself

technique · computer science · organizing-schema

Hunt and Thomas' principle: every piece of knowledge should have one authoritative representation.

DRY (Don't Repeat Yourself) was articulated by Andy Hunt and Dave Thomas in The Pragmatic Programmer (1999) as the principle that 'every piece of knowledge must have a single, unambiguous, authoritative representation within a system.' The principle is often summarized as avoiding code duplication, but Hunt and Thomas's original meaning was broader and subtler: knowledge in a system, whether expressed in code, configuration, documentation, schemas, or build scripts, should have one canonical source from which other representations are derived if needed. The pragmatic intent is preventing the divergence and inconsistency that arises when the 'same' fact is expressed in multiple places that must be kept in sync manually. Sandi Metz's 'duplication is far cheaper than the wrong abstraction' has become a widely-cited corrective: the antidote to duplication is the right abstraction, not any abstraction, and premature abstraction can be more costly than the duplication it removes. DRY is thus best understood as guidance against accidental duplication of shared knowledge, not as a prohibition on superficially similar code.

Originators

Andy Hunt; Dave Thomas high

Year / Decade

1999 (The Pragmatic Programmer) high

Primary sources

Hunt, A. & Thomas, D. (1999, 2nd ed. 2019). The Pragmatic Programmer, Metz, S. (2014). 'The Wrong Abstraction' (sandimetz.com) high

Core components

Primary use case

Code review and refactoring heuristic; teaching tool in software engineering education; widely-cited reference in clean-code and software-craftsmanship communities; basis for many code-quality and static-analysis rules.

Common criticisms

Lineage

Siblings
KISS, YAGNI, SOLID Principles