New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Provide some explanation for WHY duplicate code is bad, like mutations #1349

davidmichaelkarr opened this Issue Sep 16, 2018 · 2 comments


None yet
3 participants

davidmichaelkarr commented Sep 16, 2018

It occurs to me that none of the documentation for CPD makes any attempt to justify WHY it matters that we should look for duplicate code blocks. It's implicitly obvious to everyone reading this, but not so obvious to Joe/Mary (that doesn't sound as smooth :) ) developer who is asked to reduce the percentage of duplicate blocks in their codebase.

I can imagine why there's no statement to that effect, as again, isn't it obvious? Again, it's not.

I would suggest you add something that includes something like the following:

The real risk of having duplicate code blocks is when one of those blocks mutates slightly so it's not a duplicate anymore. This is a block that was supposed to do the exact same thing as another block, and now it's not doing the same thing. What happens if one of these blocks is duplicated again? Which one was duplicated? After some time, how do we know what the block was supposed to do anymore?


This comment has been minimized.


adangel commented Sep 17, 2018

I assume, you are referring this documentation:

I agree, this background information on the reasoning, why duplicated code can be a problem should be mentioned.

In addition to your argument (duplicated code blocks diverging over time), I'd add this:

Suppose, in a code block, which as been copied to a couple of places in the project, a bug is discovered. Now you would need to find all similar code block and apply the same fix. This increases the maintenance cost and also increases the risk, that the bug is not fixed, since it is easy to miss one duplicated code block.

Would you mind creating a proposal pull request for this? You can do this easily on github under this URL and simply edit the documentation in the browser:

After saving, this will create a fork of PMD in your github account and automatically create a new PR with your proposed changes for the documentation. Thanks!

@adangel adangel changed the title from [documentation] Provide some explanation for WHY duplicate code is bad, like mutations to [doc] Provide some explanation for WHY duplicate code is bad, like mutations Sep 17, 2018


This comment has been minimized.


davidmichaelkarr commented Sep 17, 2018

Acknowledged. I'll work on this.

@jsotuyod jsotuyod added the has:pr label Sep 25, 2018

@jsotuyod jsotuyod added this to the 6.8.0 milestone Sep 25, 2018

@adangel adangel modified the milestones: 6.8.0, 6.9.0 Sep 29, 2018

oowekyala added a commit that referenced this issue Oct 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment