SingleAuthoritativeSource

April 03, 2003
//PragDave makes a great point on his Pragmatic DRY (Don't Repeat Yourself) principle in this article:
The DRY principle says there must be a single authoritative representation of a piece of knowledge. It's worded that way for a reason: it says nothing about having lots of non-authoritative copies. So why isn't this duplication? Because (assuming an active code generator) these copies are not part of the code base. They are simply artifacts, in the same way that (say) object or class files are artifacts of the build process. The input to the code generator, which obviously is a part of the checked-in code, contains no duplication. The transient artifacts that are generated may.

Remember, the evil of duplication is that it greatly complicates the maintenance of a code base: if you need to make a change, you have to remember to alter ā€˜nā€™ different things. So even though the artifacts may contain duplicate[s], you never have to maintain that code directly: you always go back to the original input, which contains no duplication.

The article also has a great story about a project of his for British Telecom that used a single code generator to generate C code and documentation that was used to communicate with the customer. Essentially, the specs were the code.


tags: ComputersAndTechnology AgileDevelopment