← Notes

DRY Principle

🌳 Evergreen
Created: Jan 19, 2025
Updated: Jan 19, 2025

DRY stands for “Don’t Repeat Yourself” - a software engineering principle that encourages uniqueness by introducing abstractions such as variables and functions to avoid redundancy in code.

Core Idea

The DRY principle aims to reduce repetition by:

  • Creating reusable abstractions
  • Extracting common patterns into functions or variables
  • Maintaining a single source of truth for each piece of knowledge

When DRY Works Well

DRY is effective for:

  • Application code that is tested
  • Logic that truly represents the same concept
  • Reducing maintenance burden through centralization

When DRY May Not Apply

Not all repetition is bad. Consider [[DAMP]] for:

  • Configuration files
  • Test code
  • Cases where readability matters more than uniqueness