The DRY Principle
"Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."
"Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."
If the same fact is written down in two places, the two will eventually disagree, because somebody will change one and not the other. The principle says each fact should live in exactly one place, and everything that needs it should refer to that place rather than restate it.
Rated Heuristic: a dependable rule of thumb, not a proven theorem. The other 224.
Duplication is not a cost at the moment of writing; it is a cost at the moment of change. Two copies of a fact are consistent only while nobody edits them, and the probability that an edit reaches every copy falls as the copies spread and drift apart in the codebase. The failure is silent: nothing breaks when the copies diverge, so the divergence is discovered later as a bug whose cause is that the system believed two contradictory things at once. Hunt and Thomas frame the unit as knowledge rather than text, which is why the principle is about facts and not about identical-looking lines.
It names the reason maintenance costs grow faster than codebases do, and it gives the most common review comment in software a principle behind it. It also explains why so many tools exist (constants, code generation, schema-driven builds, single-source configuration) that look like indirection and are really attempts to keep one fact in one place.
Applied to text rather than to knowledge it does real harm, because it collapses things that merely resemble each other into one abstraction that then has to serve two masters. Sandi Metz's formulation of the counterweight is blunt: prefer duplication over the wrong abstraction, since duplication is cheap to fix and a wrong abstraction is not. The AHA principle, avoid hasty abstractions, makes the same point as advice about timing. Coupling is the price: every de-duplication creates a dependency, and a dependency across a boundary that should stay independent (two services, two teams, two release cycles) can cost more than the duplicate did.
It is not a ban on repeated characters, and 'DRY' is not satisfied by extracting every three-line similarity into a helper. It is also not a claim that all coupling is good: the principle says one fact should have one home, not that two unrelated systems should share code because their code looks alike.
Real as a rule of thumb, not as a theorem. The DRY Principle is rated Heuristic here: dependable enough to plan with, and with no proof behind it.
Rated from two sources. 225 of the 1,116 entries carry this rating. How the scale works.
The best-known laws are the least likely to rest on measurement.
Formulated by Andy Hunt and Dave Thomas in The Pragmatic Programmer (Addison-Wesley, 1999), where it appears with the wording given here. The opposing backronym WET, 'write everything twice', is later and informal.
9 languages, as recorded on Wikidata. These are names the idea already goes by, not translations we made. The whole index by language.
Everything above traces to pragprog.com and en.wikipedia.org, two sources in all, one of them the original publication rather than an account of it. Nothing is written from memory, and the method is written down. Spot an error or a better source? Suggest a fix.