Don't repeat yourself
From Wikipedia, the free encyclopedia
Don't Repeat Yourself (DRY, also known as Once and Only Once or Single Point of Truth (SPOT)) is a process philosophy aimed at reducing duplication, particularly in computing. The philosophy emphasizes that information should not be duplicated, because duplication increases the difficulty of change, may decrease clarity, and leads to opportunities for inconsistency. DRY is a core principle of Andy Hunt and Dave Thomas's book The Pragmatic Programmer. They apply it quite broadly to include "database schemas, test plans, the build system, even documentation." [1] When the DRY principle is applied successfully, a modification of any single element of a system does not change other logically-unrelated elements. Additionally, elements that are logically related all change predictably and uniformly, and are thus kept in sync.
Contents |
[edit] Why DRY may not be applicable
- In some small-scale contexts, the effort required to design around DRY may be far greater than the effort to maintain two separate copies of the data.
- Imposing standards aimed at strict adherence to DRY could stifle community involvement in contexts where it is highly valued, such as wikis.
- Configuration management and version control allow multiple working copies of the same code without setting aside DRY. For example, good practice generally involves setting up development, testing, and production environments so that ongoing development and testing do not affect production code.
- Human-readable documentation (from code comments to printed manuals) are typically a restatement of something in the code with elaboration and explanation for those who do not have the ability or time to read and internalize the code. However, DRY holds that if the human-readable document adds no value except the change in format, then it should be generated rather than written.
[edit] See also
- You Ain't Gonna Need It (YAGNI)
- Separation of concerns
- Database normalization
- Transaction processing (related methodology to prevent internal inconsistency)
[edit] External links
- Orthogonality and the DRY Principle
- List of Pragmatic Programmer rules
- c2.com the original
- Once and Only Once (c2.com)
[edit] References
- ^ Dave Thomas, interviewed by Bill Venners (2003-10-10). Orthogonality and the DRY Principle. Retrieved on 2006-12-01.