-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Sonar Code Quality Testing Essentials
By :

Duplicated code is simply copied and pasted at various places across a software project. When something "works", why not clone it and reuse by copying it? Code duplication is a sign of bad design raising complexity with no reason. What if the popular and duplicated code someday has to change or is buggy? Obviously, duplicated code would have to be corrected at numerous places across your project.
There are some common techniques such as method extraction to attack the problem, but in many cases, duplicated code highlights the inability of our design and the lack of flexibility usually requiring more advanced solutions. Of course, when resources are limited, refactoring and redesigning is a luxury. What we can do is correct the bug and yes, duplicate code if necessary and put redesign issues to the back burner. Sonar will trace duplicated blocks and remind us, and even alert us, when duplication reaches dangerous levels.
Don't Repeat Yourself is...
Change the font size
Change margin width
Change background colour