Welcome to EMC Consulting Blogs Sign in | Join | Help

Howard van Rooijen's EMC Consulting Blog (2004 - 2010)

This blog has now moved to http://howard.vanrooijen.co.uk/blog - please update your subscriptions if you wish to receive new content.

Detecting duplicate code with Simian

[Update = see post "MonkeyWrangler - Making Simian more usable in Visual Studio" for deeper VS integration]

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
 

Rainier van Slingerlandt said:

This is a real live saver, at my clients site they are hireing an external company to review code quality. One of the metrics is keep code duplication below 5%.

With Simian I am able to monitor the source code before the audit.

One thing I am missing is the ability to assign a list with files Simian should skip.

You see code duplication is only of intrest in hand written code.

It should skip all generated files.

But still thanks, you made my live a lot easier.

August 20, 2008 10:21
 

Duplicate code finder. | keyongtech said:

January 22, 2009 03:27
 

Howard van Rooijen's Blog said:

In my last post I talked about integrating Simian into Visual Studio - as Mal commented the default output

March 26, 2009 21:26
 

Ryan Anderson said:

For v2.2.24 users, change "-recurse=*.cs" to "-includes=**/*.cs" (notice includes plural)

April 7, 2009 00:15
 

Sneal said:

This was really helpful for me, so thanks!  I wanted clickable links in the output window so I created a <a href="http://www.sneal.net/blog/2009/04/17/RunningSimianFromVisualStudioWithClickableLinks.aspx">tiny console app that formats the Simian ouput</a> to an MSBuild clickable format.

April 17, 2009 23:25
 

Lucian Voinea said:

Another tool that you might consider is the Source Code Duplication Detector (SolidSDD): http://www.solidsourceit.com/products/SolidSDD-code-duplication-cloning-analysis.html. Not only does it detect duplicate code, but it enables also powerful analyses of the results, such as prioritizing re-factoring activities. It can be used both in GUI and command line mode, and has a broad set of mechanisms for specifying and filtering input. The tool is free for educational and Open Source projects, ans has a very affordable "supportive" license for independent developers and start-up companies.

March 23, 2010 10:49

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

News

This blog has now moved - please visit http://howard.vanrooijen.co.uk/blog for new content!
Add to Live.com
Powered by Community Server (Personal Edition), by Telligent Systems