Why duplicate code is bad?

Why duplicate code is bad?

Code which includes duplicate functionality is more difficult to support, simply because it is longer, and. because if it needs updating, there is a danger that one copy of the code will be updated without further checking for the presence of other instances of the same code.

How do you convince a colleague that code duplication is bad?

Make him realize that he is being unfair to the team & the project. If he is still not agreeing to it, get him a cup of coffee and ask him to sit by sipping it, while you could take on his keyboard and actually fix the code in front of him. He might get ashamed and not do it next time(big win).

What do you need to know about duplicate code?

What is duplicate code? Duplicate code as the name suggests is a repetition of a line or a block of code in the same file or sometimes in the same local environment. People might consider code duplication acceptable but in reality, it poses greater problems to your software than what you may have thought.

What’s the percentage of code duplication in a project?

As you can see, code duplication is mentioned under “Duplication” at the bottom. It gives an idea of the percentage of duplicate code in the project. Typically, you have some extent of duplication in your code. A general measure of controlled duplication is a limit of 5%. A project having less than 5% of code duplication is considered very good.

When does duplication occur in a programming program?

Duplication usually occurs when multiple programmers are working on different parts of the same program at the same time. Since they’re working on different tasks, they may be unaware their colleague has already written similar code that could be repurposed for their own needs.

What to do about code duplication in Java?

SonarQube indicates that SynchronizedStatementTreeImpl.java, SwitchStatementTreeImpl.java and ParenthesizedTreeImpl.java have the same code block duplicated across them. The simplest solution for the problem at hand is to define a super class, and define the duplicated blocks as code within its methods.