Common · Knowledge

Duplicate code

Piece of source code that occurs more than once in the same environment

In computer programming, duplicate code is multiple occurrences of equivalent source code in a codebase. A duplicate code fragment is also known as a code clone, and the process of finding clones in source code is called clone detection. Duplicate code has multiple undesirable aspects.

Read more

Whether fragments are classified as duplicate can be subjective. Fragments that are very small – such as a single statement – are probably not classified as duplicate. Additionally, fragments that are not exactly the same text might be considered duplicate code if they match except for less important aspects such as whitespace, comments and variable names. Even fragments that are only functionally equivalent may be classified as duplicate. Code that includes duplicate functionality is more difficult to maintain because if it needs updating, there is a risk that only some of the duplicates will be updated, leaving the others as-is. When code with a vulnerability is duplicated, the vulnerability exists in the duplicate even after it is fixed in one copy. Refactoring to eliminate duplicate code can improve many software metrics, such as lines of code, cyclomatic complexity, and coupling.

Text: Wikipédia, CC BY-SA 4.0. ·

Tap to close

Confirmation