<?xml version="1.0" encoding="ISO-8859-1"?>

<document xmlns="http://maven.apache.org/XDOC/2.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">
<properties>
<title>Duplicate code</title>
<author>Checkstyle Development Team</author>
</properties>
<body>
<section name="Duplicate code">
<p>
Duplicate code detection allows you to find
code that has been generated by Copy/Paste programming. Duplicate code typically
leads to higher maintainance cost because bugs will need to be fixed twice,
more code needs to be tested, etc.
</p>
<p>
There are many trade-offs when writing a duplicate code detection tool.
Some of the conflicting goals are:
</p>
<ul>
<li>Fast</li>
<li>Low memory usage</li>
<li>Avoid false alarms</li>
<li>Support multiple/arbitrary languages (Java, JSP, C++, ...)</li>
<li>Support Fuzzy matches (comments, whitespace, linebreaks, variable renaming, etc.)</li>
</ul>

<p>
The check provided here, StrictDuplicateCode, is fast enough to facilitate checking very large code
bases in acceptable time (minutes). It consumes very little memory, false
alarms are impossible. While it supports multiple
languages it does not support fuzzy matches (that's why it's called Strict).
</p>
<p>
Note that there are brilliant commercial implementations of duplicate code
detection tools. One that is particularly noteworthy is
<a href="http://www.redhillconsulting.com.au/products/simian/">Simian</a>
from RedHill Consulting, Inc.
Simian has managed to find a very good balance of the above tradeoffs.
It is superior to the checks in this package in many repects.
Simian is reasonably priced (free for noncommercial projects)
and includes a Checkstyle plugin.
</p>
<p>
The following table summarizes the characteristics of the available
Checkstyle plugins for duplicate code detection:
</p>

<table>
  <tr>
    <th>Name</th>
    <th>Speed</th>
    <th>Memory Usage</th>
    <th>False Alarms</th>
    <th>Supported languages</th>
    <th>Fuzzy matches</th>
  </tr>
  <tr>
    <td>StrictDuplicateCode</td>
    <td>High</td>
    <td>Very Low</td>
    <td>Impossible</td>
    <td>any language</td>
    <td>No</td>
  </tr>
  <tr>
    <td>Simian</td>
    <td>Very high</td>
    <td>Low</td>
    <td>Possible but very unlikely</td>
    <td>many languages, including Java and C/C++/C#</td>
    <td>Limited support</td>
  </tr>
</table>

<p>
<strong>
We encourage all users of Checkstyle to evaluate Simian as an
alternative to the Checks we offer in our distribution.
</strong>
</p>
</section>
<section name="StrictDuplicateCode">
<p>
 Performs a line-by-line comparison of all code lines and reports
 duplicate code if a sequence of lines differs only in
 indentation.  All import statements in Java code are ignored, any
 other line - including javadoc, whitespace lines between methods,
 etc. - is considered (which is why the check is called
 <em>strict</em>).
 </p>

 <subsection name="Properties">
 <table>
   <tr>
     <th>name</th>
     <th>description</th>
     <th>type</th>
     <th>default value</th>
   </tr>
   <tr>
     <td>min</td>
     <td>how many lines must be equal to be considered a duplicate</td>
     <td><a href="property_types.html#integer">int</a></td>
     <td><code>12</code></td>
   </tr>
   <tr>
     <td>fileExtensions</td>
     <td>file type extension of files to process</td>
     <td><a href="property_types.html#stringSet">String Set</a></td>
     <td><code>{}</code></td>
   </tr>
 </table>
 </subsection>

 <subsection name="Examples">
 <p> To configure the check: </p>
 <source>
 &lt;module name=&quot;StrictDuplicateCode&quot;/&gt;
 </source>

 <p>
 To configure the check so that it allows larger equivalent blocks:
 </p>
 <source>
 &lt;module name=&quot;StrictDuplicateCode&quot;&gt;
   &lt;property name=&quot;min&quot; value=&quot;15&quot;/&gt;
 &lt;/module&gt;
 </source>
 </subsection>

 <subsection name="Package">
 <p>com.puppycrawl.tools.checkstyle.checks.duplicates</p>
 </subsection>

 <subsection name="Parent Module">
 <p>
 <a href="config.html#Checker">Checker</a>
 </p>
 </subsection>
</section>

</body>
</document>
