Tuesday 3 February 2009

DRY (i) Don't Repeat Yourself

"Duplication may be the root of all evil in software." (ii)

Duplication slows you down and makes your code more error prone. If the same code has to be changed in more than one place you may/will miss something.

Dupliction appears in many disguises, but there are ways to deal with it so don't worry...

1) Clumps of identical code/CPS (iii). Consider using extract method or extract class followed by highlight and delete on the remaining offenders.

2) Conditional logic testing for the same set of conditions (switch/case OR if/else). Consider polymorphism.

3) Database schema. Consider using normalisation, it can be a winner

In short duplication stinks, exterminate it ruthlessly.

(i) Andy Hunt and Dave Thomas - The Pramattic Programmer
(ii) Uncle Bob - Clean Code
(iii) CPS © - Copy/Paste Syndrome - James Enock 2009)

No comments:

Post a Comment

Followers

Contributors