The Pragmatic Craftsman         :: Simplicity from complexity :: | About Me |

You are here: The Pragmatic Craftsman > Better Coder

Go to: « Special Exceptions | Architects Must Write Code »

Duplication Principle

What's the single most important thing when writing code? And practical? To me, it's the DRY, OAOO principle.

Don't know what those acronyms mean? :-) Don't Repeat Yourself, and Once And Only Once principle. Not repeating the same code in different places is the single most important thing you can do to make your project easy to maintain and to modify in the future. There are no exceptions to this rule. If you have repeated code in different places, it is a matter of time when you will see the project disintegrate. Do yourself a favor: don't copy and paste. Modify the method, break it up into two. But don't make it wet. :-)

I broke this rule numerous times. And numerous times I was sorry that I did. I did it, and I got burned. It's tempting to do so: easy and fast. But always consider the consequences.

I like my code to be clean: I like "girly" code. Duplication makes it dirty.

I can say with certainty: If your project has any duplication of logic, it is not a quality project. And after the first copy and paste, you take an express ride to a restaurant for a pasta meal. I mean "spaghetti." I mean spagheti code. :-) Do you want that?

I understand that you cannot always avoid duplication. For instance, if I have to modify an existing project, I might have to work with a lot of duplication (I hate it when I do), but for any new code that I write I have the following principle:

DUPLICATION PRINCIPLE
Duplication is my enemy. I want no enemies; therefore, I will not create any duplication and I will try to kill it whenever I see it.

References
The Pragmatic Programmers: The DRY Principle
Code like a girl, Creating Passionate Users blog
Once And Only Once, WikiWiki


Comments

Post a comment









Remember personal info?







Go to:
   « previous entry: Special Exceptions
   » next entry: Architects Must Write Code

Random Quote

Search

 

Topics

Architecture & Design :12
Better Coder :29
Books :43
Books Recommended :18
Buzzwords :5
Career :25
Craftsmanship :15
Java :15
Quotes :25
Recommended :9
Software Engineering :3
Uncategorized :33
Web Development :1

Archive

May 2008 (1)
April 2008 (2)
March 2008 (1)
February 2008 (1)
January 2008 (2)
November 2007 (1)
October 2007 (3)
August 2007 (3)

...since January 2002

Currently Reading


:: See list of books I finished reading

Info

© 2001-2008 Stanley Kubasek About me :: Contact me