Don't Repeat Yourself(DRY principle) when modifying existing function

If there is an existing  non-trivial function and you need to change it , do NOT copy and paste it , but modify to satisfy new requirements.
You may be need to split a big function into small ones and call them in different order or with different parameters.
Often you need just to add extra parameter to the function and have if-else branches depending on a new parameter.
In some cases new change is actually a fix of the problem, that applicable to all usages of the function.
Remember that "Copy and Paste" is NOT a good way of code re-use.
 
I also strongly recommend to read Exploring Smelly Code article to avoid other anti-patterns.
 
posted @ Wednesday, May 13, 2009 12:03 AM
Print

Comments on this entry:

No comments posted yet.

Your comment:



(not displayed)

 
 
 
 
 

Live Comment Preview:

 
«September»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011