DRY
/draɪ/
CommonDon't Repeat Yourself. Every piece of knowledge should exist in one place.
DRY is about knowledge, not literally about lines of code. Sometimes two pieces of code look the same but represent different concepts. Forcing them together creates wrong abstractions, which is worse than the repetition.
Real-world examples4 examples
| # | Example | What it means | Source |
|---|---|---|---|
| 01 | same validation logic in 4 different controllers. violates DRY. put it in a service. | Code review pointing out that duplicated logic should be centralized. | x, 2023 |
| 02 | fixed the date formatting bug in one place. coworker fixed it in the other place. we violated DRY for 6 months and nobody noticed. | Duplicate code led to parallel bug fixes being required, and the problem only came to light later. | reddit, 2024 |
| 03 | people forget DRY is about knowledge not lines. two functions that look the same can still be DRY if they represent different things. | Clarifying the nuance that DRY is about meaning, not just surface similarity. | x, 2024 |
| 04 | the config is defined in three places and they're all slightly different now. so DRY. | Sarcastic use, pointing out that the code failed to keep data in one place. | x, 2023 |
Use it when
- The same logic exists in multiple places and will need to change together.
- A PR copy-pastes a function from another file instead of importing it.
- Bug was fixed in one place but the duplicate was missed.
Do not use it when
- Two functions look similar but represent different domain concepts.
- You're forcing an abstraction that makes the code harder to understand.
DRY vs KISS
DRY
DRY focuses on reducing duplication so changes only happen in one place.
VS
kiss-principle
KISS focuses on keeping solutions simple and not adding unnecessary complexity.
Origin and context
Coined by Andy Hunt and Dave Thomas in their 1999 book 'The Pragmatic Programmer.' The principle is stated as: every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
- First seen
- 1999
- Confidence
- high
Cite this page
Use this stable URL to reference the entry.
https://slang.fyi/dry-principleUpdated: 2026-08-28License: CC BY 4.0