- **Epistemic status:** #budding
Don't Repeat Yourself (DRY) is a software development principle that aims to reduce repetition of software patterns by replacing the code with abstractions or using data normalization to avoid redundancy. When this principle is applied successfully, a change in a single element of a system does not require a change in other logically unrelated elements. Elements that are logically related all change predictably, keeping them in sync.
The objective with this principle is understanding that [[Code maintenance is a routine part of the development process]] to avoid a maintenance nightmare when a system needs a lot of updates that could have been done in a centralized place. This objective is similar in nature to the [[Modularity]] principle due to the construction of modules that can be re-used across an application, allowing developers to have a common API.
The principle was formulated in the book Pragmatic Programmer from authors Andy Hunt and Dave Thomas with the following statement, "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system". The principle has a broad definition that can be applied to other types of systems like database schema, test plans, UI designs, build systems, and documentation.
A test to measure if a system is dry is when changing a single facet of the code, do you have to make the change in multiple places, different formats, documentation, and/or database schema? Then it failed the test. That being said, the just because something looks the same doesn't mean it represents the same knowledge. An example can be validating age versus quantity. Both are numbers and can have the same rules, but when expanded it can get messy if kept together. [[DDD - Domain Driven Design]] tries to identify these capsules of knowledge and make them clear to everybody in a business.
---
## References
- “Don’t Repeat Yourself.” In _Wikipedia_, February 8, 2022. <https://en.wikipedia.org/w/index.php?title=Don%27t_repeat_yourself&oldid=1070635300>.
- Thomas, David, and Andrew Hunt. _The Pragmatic Programmer, 20th Anniversary Edition: Journey to Mastery_. Second edition. Boston: Addison-Wesley, 2019.