Don't repeat yourself principle
The Don’t Repeat Yourself principle is a software design guideline that gives each piece of knowledge or behavior a single authoritative representation to avoid unnecessary duplication.
A Pythonic Adventure: From Python basics to a working web app
The DRY principle is the software-development practice of avoiding duplicated knowledge or implementation by defining it once and reusing it.
- How it is used
- Replaces repeated menu-printing and input code with one reusable function.
- How deep it goes
- Works through identifying repeated and varying parts, then implements a Python function with arguments, a return value, and defaults.
- Examples
- Uses drinks, flavors, and toppings menus that collect selections for a coffee-shop order.
- What you can do after
- Build it from scratch by refactoring repeated Python menu code into a parameterized function.
Object-Oriented Software Design in C++
The Don't Repeat Yourself Principle states that every piece of knowledge or behavior should have a single authoritative representation in a system.
- How it is used
- Uses duplication as a design signal when evolving the book catalogue and consolidating repeated operations.
- How deep it goes
- Explains maintenance risks and demonstrates refactoring from duplicated subclasses to shared key–value behavior.
- Examples
- Uses fiction, cookbook, and how-to books; overloaded Catalogue operations; dynamic_cast; and key–value searches.
- What you can do after
- Apply it by consolidating repeated operations into shared functions or cohesive classes and localizing future changes.
Read how Object-Oriented Software Design in C++ explains don't repeat yourself principle →
Python Workout: 50 ten-minute exercises
The software-development principle of avoiding duplicated knowledge or logic by defining it once and reusing it.
- How it is used
- Uses functions, modules, packages, and inheritance to reduce repeated logic and improve maintainability.
- How deep it goes
- Explains motivations and reuse boundaries through Python examples, but does not develop a formal theory of duplication.
- Examples
- Uses vowel detection, reusable functions, shared modules, pricing formulas, and parent-child classes.
- What you can do after
- Build reusable Python functions, modules, and class hierarchies while recognizing repetitive expressions that deserve refactoring.
Read how Python Workout: 50 ten-minute exercises explains don't repeat yourself principle →
Effective Platform Engineering
The DRY principle is the practice of avoiding duplicated knowledge or logic by maintaining a single authoritative representation.
- How it is used
- Keeps infrastructure, credentials, and pipeline logic maintainable while reducing duplicated values and shared implementation effort.
- How deep it goes
- Explains practical implementation patterns and consequences, but stops short of broader theoretical treatment.
- Examples
- Uses secrets-manager lookups, tfvars-based environments, CircleCI orbs, shell-script libraries, and namespace-level pipelines.
- What you can do after
- Configure shared infrastructure and pipeline logic while limiting environment-specific differences to parameters and protecting credential rotation.
Read how Effective Platform Engineering explains don't repeat yourself principle →
Software Design for Python Programmers
The Don't Repeat Yourself Principle states that each piece of knowledge or behavior should have a single authoritative representation in code.
- How it is used
- Uses duplication as a practical signal for improving maintainability and avoiding designs that scale poorly with new requirements.
- How deep it goes
- Explains duplication, change leaks, and consolidation into functions or cohesive classes, but does not prescribe one universal refactoring.
- Examples
- Uses a polymorphic book catalogue and toy subclasses whose search, play, and sound implementations repeat code.
- What you can do after
- Apply it by locating repeated behavior and consolidating it into a single function or cohesive class.
Read how Software Design for Python Programmers explains don't repeat yourself principle →
The Well-Grounded Python Developer: How the pros use Python and Flask
The DRY principle is the software design principle of avoiding duplicated knowledge or logic in a codebase.
- How it is used
- Uses inheritance to centralize functionality shared by multiple Python classes and reduce inconsistent repetition.
- How deep it goes
- Explains duplication's maintenance risk and demonstrates inheritance through a growing shape-class hierarchy.
- Examples
- Uses Shape, Rectangle, Square, and Circle examples, including shared initialization and specialized drawing behavior.
- What you can do after
- Apply it via inheritance to share common attributes and behavior while specializing child classes.
Pandas Workout: 200 exercises to make you a stronger data analyst
Don't repeat yourself is a software design principle that avoids duplicating logic or equivalent code.
- How it is used
- Uses DRY to simplify repeated benchmarking while comparing dataframe serialization formats.
- How deep it goes
- Demonstrates replacing duplicated blocks with a method dictionary and loop, without developing broader design theory.
- Examples
- Benchmarks JSON, CSV, and feather writes for a NYC parking-violations dataframe.
- What you can do after
- Apply it via Python dictionaries and loops to consolidate repeated operations across related methods.
100 C++ Mistakes and How to Avoid Them
The DRY principle is the software design principle of avoiding repeated knowledge or behavior across multiple implementations.
- How it is used
- Uses DRY to establish class invariants and reduce duplicated constructor or computational behavior.
- How deep it goes
- Explains minimal function bases and demonstrates consolidation, while stopping short of treating every duplication as requiring refactoring.
- Examples
- Uses a Cylinder with repeated area and volume calculations, then centralizes initialization and derives volume from base area.
- What you can do after
- Apply it via identifying duplicated behavior and selecting a minimal set of shared operations from which other functions can be implemented.
Read how 100 C++ Mistakes and How to Avoid Them explains don't repeat yourself principle →
Python How-To
DRY is the software design principle that each piece of knowledge or behavior should have a single authoritative representation.
- How it is used
- Guides maintainability decisions by prompting programmers to identify duplication and consolidate shared behavior.
- How deep it goes
- Demonstrates duplication, extracts a variable and function, and stops short of broader refactoring patterns.
- Examples
- Uses repeated f-string alignment expressions, a configurable formatting function, and alternate width arguments.
- What you can do after
- Apply it via refactoring by replacing repeated formatting rules with shared variables or parameterized functions.
Read how Python How-To explains don't repeat yourself principle →
Python Workout, Second Edition
The DRY principle is a software-development principle that avoids duplicating knowledge or logic by expressing it once and reusing it.
- How it is used
- Uses DRY to reduce repeated logic and make Python code easier to maintain and reason about.
- How deep it goes
- Explains the maintenance rationale and demonstrates one Python refactoring, without developing broader design trade-offs.
- Examples
- Uses login, configuration, and MP3-length tasks plus a vowel-checking expression and alternative implementations.
- What you can do after
- Apply DRY via Python functions and membership testing when repeated logic or unusually long conditions appear.
Read how Python Workout, Second Edition explains don't repeat yourself principle →
Related concepts
- code duplicationaddressed by · Code duplication is the presence of equivalent or substantially similar source code or implementation logic in multiple locations within a software system.
- inheritanceused by · Inheritance is a mechanism by which a child type or element receives properties, values, or behavior from a parent, subject to system rules and possible overrides.
- decouplingaddresses · Decoupling is the design practice of reducing direct dependencies between software components so they can change, operate, or evolve more independently.
- moduleaddressed by · A module is a distinct, bounded software unit that groups related code or functionality and provides an organizational or interaction boundary within a larger system.
- functionuses · A function is a callable program unit that performs an operation, may accept inputs, and can produce a result or side effect.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.









