Wednesday, February 8, 2012 15:05

DRY Your Code

Tagged with:
Posted by on Sunday, November 1, 2009, 8:00
This news item was posted in Architecture category and has 0 Comments so far.


Don’t Repeat Yourself (DRY, also known as Single Point of Truth) 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.” 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.

The DRY code philosophy is stated as “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.” This philosophy is also 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, 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 transformation are easy to create and maintain. Tools such as XDoclet and XSLT are examples of DRY coding techniques. Examples of systems that require duplicate information are Enterprise Java Beans, which requires duplication not just in Java code but also in configuration files. Examples of systems that attempt to reduce duplicate information include the Ruby on Rails application development environment.

Data transformation skills are not taught in most junior-level software engineering courses. Current computer science curricula tend to be heavily weighted toward procedural skills such as Java, C++, or C#. The use of DRY code becomes increasingly important as developers create applications that use multi-tier architectures. The model-view-controller architectural pattern also challenges software developers to use data transformations. Developments in some language features, such as Java annotations, may allow additional metadata to be stored within object class definitions and accessed at run time, allowing features such as automatic view generation directly from models.

Reference: http://en.wikipedia.org/wiki/Don’t_repeat_yourself

Leave a Reply

You can leave a response, or trackback from your own site.