Don't repeat yourself
Encyclopedia
In software engineering
Software engineering
Software Engineering is the application of a systematic, disciplined, quantifiable approach to the development, operation, and maintenance of software, and the study of these approaches; that is, the application of engineering to software...

, Don't Repeat Yourself (DRY) is a principle of software development
Software development process
A software development process, also known as a software development life cycle , is a structure imposed on the development of a software product. Similar terms include software life cycle and software process. It is often considered a subset of systems development life cycle...

 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
Andy Hunt (author)
Andy Hunt is a writer of books on software development. Hunt co-authored The Pragmatic Programmer, six other books and many articles,...

 and Dave Thomas in their book The Pragmatic Programmer
The Pragmatic Programmer
The Pragmatic Programmer: From Journeyman to Master is a book about software engineering by Andrew Hunt and David Thomas, published in October, 1999.Characteristics of a Pragmatic Programmer: The Pragmatic Programmer: From Journeyman to Master (ISBN 0-201-61622-X) is a book about software...

. They apply it quite broadly to include "database
Database
A database is an organized collection of data for one or more purposes, usually in digital form. The data are typically organized to model relevant aspects of reality , in a way that supports processes requiring this information...

 schemas, test plan
Test plan
A test plan is a document detailing a systematic approach to testing a system such as a machine or software. The plan typically contains a detailed understanding of what the eventual workflow will be.-Test plans:...

s, the build
Software build
In the field of computer software, the term software build refers either to the process of converting source code files into standalone software artifact that can be run on a computer, or the result of doing so...

 system, even documentation
Software documentation
Software documentation or source code documentation is written text that accompanies computer software. It either explains how it operates or how to use it, and may mean different things to people in different roles....

." 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
Synchronization
Synchronization is timekeeping which requires the coordination of events to operate a system in unison. The familiar conductor of an orchestra serves to keep the orchestra in time....

. Besides using methods
Method (computer science)
In object-oriented programming, a method is a subroutine associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time...

 and subroutine
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....

s in their code, Thomas and Hunt rely on code generator
Automatic programming
In computer science, the term automatic programming identifies a type of computer programming in which some mechanism generates a computer program to allow human programmers to write the code at a higher abstraction level....

s, automatic build systems, and scripting languages to observe the DRY principle across layers.

Applying DRY

Also known as Single Source of Truth
Single Source of Truth
In Information Systems design and theory, as instantiated at the Enterprise Level, Single Source Of Truth refers to the practice of structuring information models and associated schemata such that every data element is stored exactly once...

, this philosophy is prevalent in model-driven architecture
Model-driven architecture
Model-driven architecture is a software design approach for the development of software systems. It provides a set of guidelines for the structuring of specifications, which are expressed as models. Model-driven architecture is a kind of domain engineering, and supports model-driven engineering of...

s, in which software artifacts are derived from a central object model expressed in a form such as UML
Unified Modeling Language
Unified Modeling Language is a standardized general-purpose modeling language in the field of object-oriented software engineering. The standard is managed, and was created, by the Object Management Group...

. DRY code is created by data transformation
Data transformation
In metadata and data warehouse, a data transformation converts data from a source data format into destination data.Data transformation can be divided into two steps:...

 and code generators, which allows the software developer to avoid copy and paste
Cut and paste
In human-computer interaction, cut and paste and copy and paste offer user-interface interaction techniques for transferring text, data, files or objects from a source to a destination. Most ubiquitously, users require the ability to cut and paste sections of plain text...

 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
XDoclet
XDoclet is an open-source code generation library that enables Attribute-oriented programming for Java via insertion of special Javadoc tags. It comes with a library of predefined tags, which simplify coding for various technologies: Java EE, Web services, Portlet etc.-Example:A typical XDoclet...

 and XSLT
XSLT
XSLT is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized by the processor in standard XML syntax or in another format,...

 are examples of DRY coding techniques. Examples of systems that require duplicate information are 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
Symfony
Symfony is a web application framework written in PHP which follows the model-view-controller paradigm. Released under the MIT license, Symfony is free software...

, web2py
Web2py
Web2py is an open source web application framework. Web2py is written in the Python language and is programmable in Python. Since web2py was originally designed as a teaching tool with emphasis on ease of use and deployment, it does not have any project-level configuration files. Web2py was...

 and Django web frameworks, Ruby on Rails
Ruby on Rails
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.-History:...

 application development environment and Enterprise Java Beans version 3.

Kent Beck
Kent Beck
Kent Beck is an American software engineer and the creator of the Extreme Programming and Test Driven Development software development methodologies. Beck was one of the 17 original signatories of the Agile Manifesto in 2001....

 has mentioned that he does not "subscribe to [DRY] for test code because [he] want[s] [his] tests to read like a story".

See also

  • Abstraction principle (programming)
    Abstraction principle (programming)
    In software engineering and programming language theory, the abstraction principle is a basic dictum that aims to reduce duplication of information in a program whenever practical by making use of abstractions provided by the programming language or software libraries...

  • Code reuse
    Code reuse
    Code reuse, also called software reuse, is the use of existing software, or software knowledge, to build new software.-Overview:Ad hoc code reuse has been practiced from the earliest days of programming. Programmers have always reused sections of code, templates, functions, and procedures...

  • Single Source of Truth
    Single Source of Truth
    In Information Systems design and theory, as instantiated at the Enterprise Level, Single Source Of Truth refers to the practice of structuring information models and associated schemata such that every data element is stored exactly once...

  • Occam's Razor
    Occam's razor
    Occam's razor, also known as Ockham's razor, and sometimes expressed in Latin as lex parsimoniae , is a principle that generally recommends from among competing hypotheses selecting the one that makes the fewest new assumptions.-Overview:The principle is often summarized as "simpler explanations...

  • Separation of concerns
    Separation of concerns
    In computer science, separation of concerns is the process of separating a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors...

  • KISS principle
    KISS principle
    KISS is an acronym for the design principle Keep it simple, Stupid!. Other variations include "keep it simple and stupid", "keep it short and simple", "keep it simple sir", "keep it simple or be stupid" or "keep it simple and straightforward"...

  • You Ain't Gonna Need It
    You Ain't Gonna Need It
    "You ain't gonna need it" is the principle in extreme programming that programmers should not add functionality until it is necessary...

  • Rule of three (programming)
    Rule of three (programming)
    Rule of three is a code refactoring rule of thumb to decide when a replicated piece of code should be replaced by a new procedure. It states that you are allowed to copy and paste the code once, but that when the same code is replicated three times, it should be extracted into a new procedure...

  • Redundancy (engineering)
    Redundancy (engineering)
    In engineering, redundancy is the duplication of critical components or functions of a system with the intention of increasing reliability of the system, usually in the case of a backup or fail-safe....

  • Mirror (computing)
    Mirror (computing)
    In computing, a mirror is an exact copy of a data set. On the Internet, a mirror site is an exact copy of another Internet site.Mirror sites are most commonly used to provide multiple sources of the same information, and are of particular value as a way of providing reliable access to large downloads...


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK