-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathMostlyDuplicateFile.qhelp
More file actions
31 lines (26 loc) · 1.57 KB
/
MostlyDuplicateFile.qhelp
File metadata and controls
31 lines (26 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>If two files share a lot of each other's code then there is a lot of unnecessary code duplication.
This makes it difficult to make changes in future and makes the code harder to read.</p>
</overview>
<recommendation>
<p>While completely duplicated files are rare, they are usually a sign of a simple oversight.
Usually the required action is to remove all but one of them. A common exception to this rule may arise
from generated code that simply occurs in several places in the source tree; the check can be
adapted to exclude such results.</p>
<p>It is far more common to see duplication of many lines between two files, leaving just a few that
are actually different. Consider such situations carefully. Are the differences deliberate or
a result of an inconsistent update to one of the clones? If the latter, then treating the files as
completely duplicate and eliminating one (while preserving any corrections or new features that
may have been introduced) is the best course. If two files serve genuinely different purposes but almost
all of their lines are the same, that can be a sign that there is a missing level of abstraction. Look
for ways to share the functionality, either by creating a utility class for the common parts or by
encapsulating the common parts into a new super class of any classes involved.</p>
</recommendation>
<references>
<li>Elmar Juergens, Florian Deissenboeck, Benjamin Hummel and Stefan Wagner. <em>Do Code Clones Matter?</em>. 2009.</li>
</references>
</qhelp>