Friday, March 9, 2012

Finding Bad Smells in Code

Recently we did an assignment on finding bad smells in code. For this I and my colleagues found couple of tools which we can do this task. This was very useful when your source code is way too big as you don't have to go through each and every bit of code. So for the benefit of the people who is reading I would briefly mention the tools we have used and some references where you can get more information. keep in mind that all of these tools are only applicable for java source codes.

1.) Code bad Smell detector
As the blog describes this can detect five of the bad smells in a Java code. ( Data Clumps, Switch Statements, Speculative Generality, Message Chains, and Middle Man)
I integrated this to Netbeans and used it.
Following steps describes how to integrate this into netbeans.

-download the source files from here.
-open this source in netbeans. New Project -> Java -> Java Project with existing sources. (Here you can add the extracted source folder which you have downloaded to the project)
-add these jar files to the library folder (if you encounter runtime errors you can add the other jar files here apart from the listed below)
junit-4.4.jar , mysql-connector-java-5.0.4-bin.jar , recoder.jar , commons-httpclient-3.1.jar , commons-logging-1.1.1.jar , commons-codec-1.3.jar
-Go to project properties -> Run -> set the main class to "BadSmellDetector". 
-As arguments set these;
1st arg : give the source code path you want to find the bad smell
2nd arg : -x (for XML output) , -g (for JFrame)

2.) JDeodorant 
an eclipse plugin which can detect four types of bad smells in the code. (Feature Envy, Type Checking, Long Method and God Class) visit the site
-download the plugin from this site. 
-put the jar file to eclipse -> dropins -> plugin directory and start the eclipse and you are ready to go. 
-refer this video to get an idea how you can view each bad smell using this.
 
3.) Vanaraha
this is another eclipse plugin where you can detect the duplicate code. 
 visit the site to download the plugin.
Like I mentioned for JDeodorant you can 
Put the jar file to eclipse -> dropins -> plugin directory and start the eclipse and you are ready to go.

4.) FindBugs
this is another tool can be integrated to your favorite IDE. Some of my colleagues successfully integrated this to IDEA. And I tried implementing this to Netbeans. Here is a blog post written how to integrate the plugin to Netbeans 6.0. For some reason I couldn't integrate this to my version of netbeans (7.0.1).

1 comment:

anshu singla said...

plzzz help
when i choose any option from bad smell menu then msg come dat choosen operation is not currently availble