mirror of
https://github.com/github/codeql.git
synced 2025-12-25 13:16:33 +01:00
49 lines
1.5 KiB
XML
49 lines
1.5 KiB
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
<overview>
|
|
<p>
|
|
Duplicate functions with identical or very similar bodies indicate poorly structured
|
|
code that is hard to maintain. The artificially inflated amount of code hinders comprehension,
|
|
and ranges of similar but subtly different lines can mask the real purpose or intention behind
|
|
a function. Duplicate functions can also suffer from update anomalies, where only one of several
|
|
copies of the code is updated to address a defect or add a feature, causing them to slowly
|
|
evolve apart.
|
|
</p>
|
|
|
|
<p>
|
|
In some cases, duplicate functions can also indicate a bug where a function was copied
|
|
with the aim of changing it in some way, but the programmer then forgot to perform the
|
|
intended change.
|
|
</p>
|
|
|
|
</overview>
|
|
<recommendation>
|
|
|
|
<p>
|
|
At its simplest, function duplication can be addressed by removing all but one of the
|
|
duplicate function definitions and making callers of the removed functions refer to the
|
|
(now canonical) single remaining definition instead.
|
|
</p>
|
|
|
|
<p>
|
|
If two functions are mostly, but not completely, identical, it is often possible to factor
|
|
out the common functionality into a new function. This improves reusability and resolves
|
|
the code duplication.
|
|
</p>
|
|
|
|
|
|
</recommendation>
|
|
<references>
|
|
|
|
|
|
<li>Elmar Juergens, Florian Deissenboeck, Benjamin Hummel, and Stefan Wagner. 2009.
|
|
Do code clones matter? In <em>Proceedings of the 31st International Conference on
|
|
Software Engineering</em> (ICSE '09). IEEE Computer Society, Washington, DC, USA,
|
|
485-495.
|
|
</li>
|
|
|
|
</references>
|
|
</qhelp>
|