Glossary · Programming

DRY (Don't Repeat Yourself)

DRY is a software principle stating that each piece of knowledge should have a single, authoritative representation in a codebase.

Updated October 6, 2026

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.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.