Code on a screen, representing the DRY principle.

Don't repeat yourself in code.

What the DRY principle is

The DRY principle, which stands for don't repeat yourself, is a software development guideline aimed at reducing repetition. It states that every piece of knowledge or logic in a system should have a single, authoritative representation. In other words, you should avoid duplicating the same information or logic in multiple places, and instead define it once and reference it where needed.

Avoiding duplication

The core idea of DRY is to avoid duplication of knowledge. When the same logic or information is copied in several places, the system becomes harder to maintain. The principle encourages capturing each piece of knowledge in one place, so there is a single source of truth. This keeps the codebase cleaner and reduces the scattering of the same idea across many locations.

Why duplication causes problems

Duplication is problematic because when the duplicated knowledge needs to change, every copy must be updated. If any copy is missed, the system becomes inconsistent, leading to bugs. Keeping multiple copies in sync is error-prone and tedious. By avoiding duplication, the DRY principle removes this burden, since a change only needs to be made in one place.

A single source of truth

Following DRY means establishing a single, authoritative place for each piece of knowledge. When that knowledge changes, you update it in one spot, and everything that relies on it reflects the change. This single source of truth makes the system more consistent and easier to maintain, which is the central benefit the DRY principle aims to provide.

Applying DRY thoughtfully

While DRY is valuable, it is applied with judgment, since not all apparent repetition represents the same underlying knowledge. The goal is to avoid duplicating genuine pieces of knowledge, not to force unrelated things together. Understanding DRY clarifies the aim of reducing meaningful duplication so that each piece of knowledge lives in one authoritative place.

Why it matters

The DRY principle is an important guideline in software development. Understanding what it is - avoiding duplication by giving each piece of knowledge a single representation - clarifies how to keep code maintainable and consistent. For anyone writing software, it is a valuable concept to understand.

See also: What is refactoring? Explained, What is a code smell? Explained.

Sources

Published date reflects the original event date (2026-10-15). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.

Skillo Staff

Skillo Staff

All stories by: Skillo Staff

Leave a Reply