mirror of
https://github.com/github/codeql.git
synced 2025-12-28 06:36:33 +01:00
44 lines
2.0 KiB
XML
44 lines
2.0 KiB
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
|
|
|
|
<overview>
|
|
<p>When most of the methods in one class are duplicated in one or more other classes,
|
|
the classes themselves are regarded as <em>mostly duplicate</em>.</p>
|
|
|
|
<p>Code duplication in general is highly undesirable for a range of reasons. The artificially
|
|
inflated amount of code is more difficult to understand, and sequences of similar but subtly different lines
|
|
can mask the real purpose or intention behind them. Also, there is always a risk that only one
|
|
of several copies of the code is updated to address a defect or add a feature.</p>
|
|
|
|
</overview>
|
|
<recommendation>
|
|
<p>Although completely duplicated classes are rare, they are usually a sign of a simple
|
|
oversight (or deliberate copy/paste) by a developer. Usually the required solution
|
|
is to remove all but one of them.</p>
|
|
|
|
<p>It is more common to see duplication of many methods between two classes, leaving just
|
|
a few that are actually different. Decide whether the differences are
|
|
intended or the result of an inconsistent update to one of the copies:</p>
|
|
<ul>
|
|
<li>If the two classes serve different purposes but many of their methods are duplicated, this indicates
|
|
that there is a missing level of abstraction. Introducing a common super-class to define the
|
|
common methods is likely to prevent many problems in the long term. Modern IDEs may provide
|
|
refactoring support for this sort of issue, usually with the names "Pull up" or "Extract supertype".</li>
|
|
<li>If the two classes serve the same purpose and are different only as a result of inconsistent updates
|
|
then treat the classes as completely duplicate. Determine
|
|
the most up-to-date and correct version of the code and eliminate all near duplicates. </li></ul>
|
|
|
|
</recommendation>
|
|
<references>
|
|
|
|
<li>E. Juergens, F. Deissenboeck, B. Hummel, S. Wagner.
|
|
<em>Do code clones matter?</em> Proceedings of the 31st International Conference on
|
|
Software Engineering,
|
|
485-495, 2009.</li>
|
|
|
|
</references>
|
|
</qhelp>
|