6

Is there a tool to finding redundancy through out a set of library code (.net C#)?

The problem is I have a number of .NET libraries, but they tend to have a lot of similar/duplicate "helper" or "utility" functions. Some times the code may not be exactly utility, but follows similar patterns with slightly different naming.

Is there a tool of some kind that can spot these similarities and report them on a batch of C# libraries?

lucidquiet
  • 5,441
  • 7
  • 37
  • 76

3 Answers3

4

Visual Studio 11 (currently only a developer preview) has this functionality. You can download the Developer Preview for free to check it out.

It's called Code Clone Analysis and it searches trough your code looking for similarities and generates a report that varies from exact matches to probable matches.

Here you can find a small example.

Wouter de Kort
  • 36,302
  • 10
  • 78
  • 99
4

CodeRush now has a Duplicate Code finder built in. I don't know what your budget is for such a tool, but I find the benefits of CodeRush / Refactor! to more than offset the cost of the licence.

ZombieSheep
  • 28,629
  • 10
  • 64
  • 112
3

See our CloneDR tool for finding exact and near-miss blocks of duplicate code across large bodies of source code.

CloneDR works by parsing the source text using a compiler-quality front end, building compiler data structures ("AST"s) that represent the code, and matching the trees. This means it can find duplicates in spite of layouts, line breaks or comments. The matching process can find code blocks that are similar in the sense that can be parameterized; it easily find similar blocks with renamed variables, or with statements or blocks of code that have been replaced.

There are versions for many languages, including C#. A sample C# clone detection report can be found at the website.

CloneDR is not a "development preview". I wrote one the original papers on how to do this well back in 1998 and have been developing CloneDR ever since; see Clone Detection Using Abstract Syntax Trees. (The Microsoft Clone detector does token-based, not tree-based clone detection, and produces, IMHO, answers that are not as good; in fact, such token-style detectors are why I wrote the paper).

Ira Baxter
  • 88,629
  • 18
  • 158
  • 311
  • CloneDR isn't a free tool right? And I don't think there is a trial for this tool either -- is that correct? – lucidquiet Dec 07 '11 at 17:10
  • CloneDR is a commercial tool. There are evaluation downloads easily obtained from the site. (MS Studio comes in several styles, some of which are not free, either; I don't know which version will contain the MS clone detection tool) – Ira Baxter Dec 07 '11 at 17:16