Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to consolidate code duplicates [closed]

We're using a code static analysis tool (Sonar) to detect duplicate code on our project. It appears that there are a great many instances of duplicates in the code but most of them are less than 10 lines and occur only once. In the 'opinion' of the Stackoverflow community, Where should you draw the line at consolidating code duplications? For example should it be at >= 10 lines for individual duplicates or should you consider overall number of lines duplicated eg. consider > 10 duplicates that occur more than once. For context the programming languages I'm looking at are Java and ActionScript. I realize that this question may not come to a definitive answer but some clear guidance on this matter could save me a lot of time refactoring code (or increase the time:)

like image 580
Fergal Avatar asked Dec 12 '25 04:12

Fergal


1 Answers

If they are actual duplicates, consolidate as soon as you can. The longer you leave it, the more the copies will diverge and the harder it will be. Also, when someone comes across a pile of copies and needs to do a "quick fix" they will make more copies, but a nice clean codebase encourages everyone to keep it clean.

like image 193
Matt Curtis Avatar answered Dec 14 '25 19:12

Matt Curtis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!