14

I am a strong advocate of the DRY principle:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

Are there any tools that can test a code base for the amount of DRYness and both quantify and pinpoint specific examples for correction?

Scott Stafford
  • 43,764
  • 28
  • 129
  • 177

4 Answers4

3

Simian

Simian (Similarity Analyser) identifies duplication in Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy source code and even plain text files. In fact, simian can be used on any human readable files such as ini files, deployment descriptors, you name it.

Simian runs natively in any .NET 1.1 or higher supported environment and on any Java 5 or higher virtual machine, meaning Simian can be run on just about any hardware and any operating system you can hope for. Both the Java and .NET runtimes are included as part of the distribution.

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
2

PMD's Copy Past Detector (CPD)

Duplicate code can be hard to find, especially in a large project. But PMD's Copy/Paste Detector (CPD) can find it for you!

Note that CPD works with Java, JSP, C, C++, Fortran and PHP code.

You can run it commandline, there is an ANT task, and an Eclipse plugin.

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
1

Clone Detective for Visual Studio

Clone Detective is a Visual Studio integration that allows you to analyze C# projects for source code that is duplicated somewhere else. Having duplicates can easily lead to inconsistencies and often is an indicator for poorly factored code.

enter image description here

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
0

See our CloneDR tool, which finds exact and near miss sets of duplicated code using computer langauge structure as guide. As well as detecting clones, it will show you a rough abstraction and the parameter bindings that explain the differences between the clone instances.

It has instantiations for many lanuages: C, C++, C#, Java, JavaScript, PHP, COBOL, Python, PLSQL, ... It tends to find 10-15% duplicated code across systems that have any serious size (e.g, 100K SLOC and above). There are sample reports for many languages at the web site, and you can download a trial copy.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • 1
    I tried to use this - had to fill out a trial form (annoying), clicked the "Project Specifier" link (unusual, confusing, and broken), retried the command that tried on cmdline to finally launch it, tried to nav to my source directory, during which it hung. Then I gave up. This thing needs UI work. – Scott Stafford May 17 '12 at 20:17
  • @ScottStafford: Sorry you had a bad experience. Which version of the CloneDR did you run, for which language, and on which OS? We have rather a lot of combinatorics and sometimes that gets us. If its broken we'd obviously like to fix it. Normally it runs fine. – Ira Baxter May 18 '12 at 02:10
  • @ScottStafford: Actually, its a little hard to tell from your description just exactly what hung. Would you be willing to email a screenshot and some explanatory text to support@semanticdesigns.com? – Ira Baxter May 18 '12 at 02:21