Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[doc] Update cpd.md with information about risks #1361
The current CPD documentation covers very well how to use it, but there was no information here that describes why someone would care about how much duplicate code they have. The developers I work with want to "cheat" on their SonarQube quality gates by excluding some code from CPD checks, because they don't really understand what the problem is. Ironically, the main risk from duplicate code is when that code unintentionally becomes not duplicate anymore, creating a hidden problem that may or may not erupt on you.
The text I've added here is excerpted from a short tech note I wrote to my team on the subject.
Before submitting a PR, please check that:
On Sun, Oct 14, 2018 at 2:22 AM Andreas Dangel ***@***.***> wrote: ***@***.**** commented on this pull request. ------------------------------ In docs/pages/pmd/userdocs/cpd.md <#1361 (comment)>: > @@ -30,6 +30,33 @@ See how to add it [here](/pmd_devdocs_adding_new_cpd_language.html). CPD is included with PMD, which you can download [here](http://sourceforge.net/projects/pmd/files/pmd/). +### Why should you care? + +It's certainly important to know where to get CPD, and how to call it, but it's worth stepping back for a moment and asking yourself why you should care about this, being the occurrence of duplicate code blocks. + +#### If nothing ever changes, the impact is minimal + +If you're analyzing code that never changes, it's reasonable to assume that you don't need to care too much about this. Risk comes in when you're working with complex code that can change over time. + +#### Refactoring known duplications can be messy Maybe we should mention the DRY-Principle <https://en.wikipedia.org/wiki/Don%27t_repeat_yourself>, since that's the thing, that CPD tries to enforce: avoiding repetition/duplication of parts, that look the same (and hence seem to be related in some way) and should therefore be refactored, to avoid the risks you mentioned.
It's certainly worthwhile to mention that. I note that from a very brief survey of DRY citations, I don't see any that try to address what we're trying to address here, which are enumerating the risks of not following that recommendation. It's an "obvious" thing to do, clearly.…
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#1361 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AFTv0-Uy2-dKtX-DLtB0mDlc9Sl2isPCks5ukwI-gaJpZM4W5i1H> .
changed the title from
Update cpd.md with information about risks
[doc] Update cpd.md with information about risks
Oct 17, 2018
Oh. I was sort of surprised to see this merged, considering the discussion that had been going on about it. I'm not complaining, but I did think some reasonable points were being presented. On the other hand, maybe it's better to just get this out there and see how it feels.