Don't repeat yourself (DRY)

Don't repeat yourself (DRY)

Duplication (inadvertent or purposeful duplication) can lead to maintenance nightmares, poor factoring, and logical contradictions.

Duplication, and the strong possibility of eventual contradiction, can arise anywhere: in architecture, requirements, code, or documentation. The effects can range from mis-implemented code and developer confusion to complete system failure.

The DRY (Don't Repeat Yourself) Principle states: Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

Don't repeat yourself

In software engineering, don't repeat yourself (DRY) is a principle of software development, a principle aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures. The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." The principle has been formulated by Andy Hunt and Dave Thomas in their book The Pragmatic Programmer. They apply it quite broadly to include "database schemas, test plans, the build system, even documentation." When the DRY principle is applied successfully, a modification of any single element of a system does not require a change in other logically unrelated elements. Additionally, elements that are logically related all change predictably and uniformly, and are thus kept in sync. Besides using methods and subroutines in their code, Thomas and Hunt rely on code generators, automatic build systems, and scripting languages to observe the DRY principle across layers.

Applying DRY Rule

Also known as Single Source of Truth, this philosophy is prevalent in model-driven architectures, in which software artifacts are derived from a central object model expressed in a form such as UML. DRY code is created by data transformation and code generators, which allows the software developer to avoid copy and paste operations. DRY code usually makes large software systems easier to maintain, as long as the data transformations are easy to create and maintain. Tools such as XDoclet and XSLT are examples of DRY coding techniques. An example of a system that requires duplicate information is Enterprise Java Beans version 2, which requires duplication not just in Java code but also in configuration files. Examples of systems that attempt to reduce duplicate information include the Symfony, web2py, Yii, Play Framework and Django web frameworks, EiffelStudio, Ruby on Rails application development environment, Microsoft Visual Studio LightSwitch and Enterprise Java Beans version 3.

DRY vs WET solutions

Violations of DRY are typically referred to as WET solutions, which is commonly taken to stand for either "write everything twice" or "we enjoy typing".

Don't repeat yourself (DRY)
added 10 years 4 months ago

Contents related to 'Don't repeat yourself (DRY)'

There's more than one way to do it (TMTOWTDI): "There's more than one way to do it" is a Perl programming motto. The language was designed with this idea in mind, in that it "doesn't try to tell the programmer how to program."

- The Configuration Section Cannot Contain a CDATA or Text Element
- What is horsepower? Kw hp conversion
- A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.ServiceModel.dll
- A first chance exception of type 'System.ServiceModel. CommunicationObjectAbortedException' occurred in System.ServiceModel.dll
- System.AccessViolationException: Attempted to read or write protected memory
- How to download attachments from outlook
- How to add Startup items to Windows 8
- How to forward IP-Port on Windows Machine
- There's more than one way to do it (TMTOWTDI)
- Don't repeat yourself (DRY)