blogs.conchango.com

welcome to the conchango blogging site
Welcome to blogs.conchango.com Sign in | Join | Help
in Search

Howard van Rooijen's Blog

Detecting duplicate code with Simian

One of the easiest “code smells” to deodorise is that of "duplicate code" - Simian is a Similarity Analyser that detects duplications in source code (C#, C, C++ ASP, XML etc); once detected you can easily locate the duplication and perform an "Extract Method" refactor in Visual Studio. Simian is a command line tool - but you can integrate it into Visual Studio via the extensibility of the External Tools menu.

The best way to configure Visual Studio to use Simian is to add seperate entries that will examine the whole solution, the current project and the current file:

Scan Whole Solution:

Scan Current File:

If you're wondering what $(ItemFileName) and $(ItemExt) mean - read the MSDN article "Arguments for External Tools".

Scan Current Project:

You can then add keyboard short-cuts to the external tools – for example below shows the keyboard options dialog for the mapping of Ctrl-Alt + \ I used for “Scan Solution” :

To find out the name of the external command you have created simply count the position of the item after “Create Guid” – Simian is 7th therefore it’s ExternalCommand7:

Published 08 February 2006 14:36 by howard.vanrooijen
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Tareq Muhammad said:

Hi,
That is very cool tool, thanks howard
Note: you blog is wonderful.
February 8, 2006 16:19
 

silk and spinach said:

Being a link showing how to integrate Simian with Visual Studio
February 9, 2006 09:20
 

Mal Ross said:

Hi Howard,

Great to see someone else doing this too. :)

However, the one thing I find it lacks is the ability to double-click on Simian's output to take me to the relevant line of code. I believe that if the output is formatted as:

BadCode.cs(87) : duplicated code up to line 96
BadCode.cs(143) : duplicated code up to line 152

then it should be possible to double-click the output to take us there (may need the full file path, actually - not sure). Do you know of any little tool that takes the output of Simian and converts it to this form? Or do you know of a DOS tool that could convert it? For me, that would be the final piece in the jigsaw.
February 15, 2006 14:23
 

howard.vanrooijen said:

Hi Mal, I've started to write a shim control to do exactly that. If I get anywhere with it - I'll post the source.
February 15, 2006 16:10
 

Howard van Rooijen's Blog said:

In my last post I talked about integrating Simian into Visual Studio - as Mal commented the default output...
February 18, 2006 14:20
 

Bjorn Reppen said:

Brilliant!
March 15, 2006 12:20
 

s said:

Does Simian works on .Net 2.0 assemblies? Their page doesn't explicitly say that.
March 15, 2006 23:56
 

howard.vanrooijen said:

S,

Simian does not work against assemblies (it's not like reflector) - just the source files (it works against any humanly readable text file).

The actual Simian App has a .NET 1.1 version but this can be used against any text file.
March 16, 2006 08:34
 

Chris Burrows .NET Blog said:

A while back I mentioned a Java application that searches for code duplication called Simian.  ...
March 16, 2006 10:01
 

Morgan said:

For 2.2.14 users, change "-recurse=*.cs" to "-include=**/*.cs"
February 20, 2007 16:00
 

Anthony Steele's Blog : Don't repeat yourself said:

February 26, 2007 15:12
 

integrating simian with visual studio « silk and spinach said:

May 12, 2007 14:37
 

Jason said:

I tired but there was no result come out, I use 2.2.17 with the argument "-include=**/*.cs", anybody know why? thanks
June 6, 2007 10:01
 

Anthony Steele's Blog said:

I spent a year in the late 1990s working in small company. We asked prospective hires to submit code

June 12, 2007 20:49
 

Jonathan Evans said:

Even better integration can be achieved by getting the results back in the correct format, I use these arguments: -formatter=vs -language=cs $(ProjectDir)/**/*.cs With "Use Output Window" checked I am able to click on lines in the results and see them highlighted in the code window.
July 5, 2007 16:11

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Personal Edition), by Telligent Systems