DRY (Don't Repeat Yourself) is a software design principle, popularized by the book "The Pragmatic Programmer", stating that every piece of knowledge should have a single, unambiguous, authoritative representation within a system. It targets duplicated logic and facts, not merely similar-looking lines.
Why it matters
When the same rule is copied into several places, a change must be made everywhere, and missing one creates inconsistent behavior and bugs. Centralizing the rule in a function, constant, configuration value or schema makes changes safe and quick. Applied too eagerly, DRY produces premature abstractions: two pieces of code that look alike but change for different reasons get merged into a tangled shared helper full of flags. Many developers wait until a pattern appears three times before extracting it.
Example
Repeated:
const a = price * 1.18; // tax in cart
const b = total * 1.18; // tax in invoice
DRY version:
const TAX_RATE = 0.18;
const withTax = amount => amount * (1 + TAX_RATE);
Common mistakes
- Merging code that is only coincidentally similar.
- Creating a helper with many boolean parameters to cover every variation.
- Applying DRY across service boundaries, creating tight coupling.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.