Don't Repeat Yourself (DRY)
- Categories
- Complexity
Every piece of knowledge must have a single, authoritative, unambiguous representation in a system. DRY is about duplicated knowledge and intent, not merely duplicated lines of code; two pieces of code can look alike yet represent different knowledge, and identical knowledge can be expressed in different-looking places.
Why it Matters
When one fact lives in several places, every change must find and update them all, and the copies drift out of sync. A single source of truth removes that change amplification and the bugs that come from inconsistent copies.
Signals
- The same rule, constant, or schema restated in code, config, docs, and tests.
- A change that requires the same edit in several places to stay correct.
- Copies that have quietly diverged.
Benefits
Changes happen in one place, consistency is structural rather than maintained by discipline, and the system is cheaper and safer to modify.
Risks
False DRY: forcing two things that merely look alike into one abstraction couples unrelated knowledge, so later they need to differ and the abstraction fights you. Some duplication is healthier than the wrong coupling.
Tensions
DRY pulls toward sharing and abstraction, while orthogonality and decoupling sometimes favor a little duplication over a dependency. The test is whether the knowledge is genuinely the same, not whether the code looks the same.
Examples
Generating client and server validation from one schema rather than coding the rules twice; deriving a value instead of storing it in two records that can disagree.