views:

337

answers:

6

In the near future, I will be inheriting a somewhat large project. I've been making some small updates to it recently, and noticed that parts of it could use some refactoring, since there are methods that perform the same operation with a small difference.

I was wondering if there is a tool that will take a bunch of source code and find similar blocks of code so that they could be identified for possible refactoring. It would be great if there was fuzzy searching present, so that it could identify similar operation (other than just chucks of code repeated verbatim).

I don't expect the program to refactor the code itself, just identify potential repetition.

My platform is C#, but any solution would be helpful

+4  A: 

CPD works at the token level, so should be fine with C#. It has some mechanisms for factoring out variable names and other identifiers too.

Michael Donohue
+6  A: 

http://www.codeplex.com/CloneDetectiveVS

"Clone Detective is a Visual Studio integration that allows you to analyze C# projects for source code that is duplicated somewhere else."

There's a lot going on, visually, when you throw it at a project with a lot of code duplication. If that combines with your using Clone Detective for the first time, it can be a bit overwhelming at first.

I really recommend this tool. It is excellent.

lance
The code I'm inheriting is currently .Net 1.1 (obviously requiring VS .NET) so this won't help me on this project until we update it for at least 2.0. But this will help with every other project i am currently on! Will take a look, +1
phsr
Selected as answer because: It integrates into my current IDE for most project; Great interface; and its open source. Simian looks nice, but I plan to use this in a commercial environment and the cost is prohibitive (for me)
phsr
ALthough it may not be an issue as of September 2010 Clone Detective does not appear to support Visual Studio 2010
Jafin
+5  A: 

I've never used it, but Simian might work for you

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.

Scott Weinstein
Just to note, I have used Simian, and I won't bother to do so again. I certainly wouldn't recommend it to anyone. I have also used Clone Detective, and it is an excellent application.
MagicAndi
+2  A: 

Simian is a product that claims to analyze source code in various languages, including C#. I've never used it, so I can't vouch for it at all. It's free for non-commercial use, and they'll sell it to you for commercial projects.

aem
+2  A: 

I've used Simian several times against java and ruby code bases and it worked quite well. Seems that it supports c# as well. http://www.redhillconsulting.com.au/products/simian/overview.html

Drew Olson
+3  A: 

I'm currently using Duplicate Finder. It works on any text file, and I've been using it on my C# projects, very successfully. It's command line, so I've integrated it into my build processes.

jwmiller5