h1

Results of SourceMonitor on my current project

June 29, 2008

Well last week Richard from Readify had been called in to help us here at my current engagement – Carlson Marketing. While he was here he pointed me to a few programs that I had not known about. One of them was called SourceMonitor. What it does is basically run some metrics against your code to see how clean and how well/poorly written your code is. Before I start keep in mind that the max code complexity and average code complexity should be between 5 and 15. We ran it against some of the code that was contracted off to an offshore company in india and the results that came back were extremely poor (max code complexity of 80). Rather than bagging out what a poor job they had done I decided to see if my own code that I had written myself was any better. I consider myself to be fairly padantic about the way code is written and try to keep it simple as best I can. I decided to run it against one of my more complex projects here to try and get my worst case scenarios. Here are the results SourceMonitor-profile-code-complexity-metrics

 

as I suspected one of my methods is too long and is too complex. The method basically maps a business object from a web service that’s hosted somewhere across the world. There are many properties on the class that need to be mapped each with fairly complex business logic(s). From this we can see that I have not written enough comments and have a single method that is slightly too complex. On average tho we can see that the rest of the code is fine. It is one problematic method that is throwing everything off a little. I have not gone back to refactor this code as it has been code reviewed by fellow senior devs and we agree that it is an exceptional case and that it is written well. The idea isn’t to stick between the green area 100% of the time but rather to get a rough idea on how well your code has been written. If you genuinely write clean, simple code, I think you will be surprised at how often your code will hti the sweet spot of that green circle.

Here are the results of the code that the offshore company had written: offshore-company-code-complexity-metrics

As you can see the max code complexity is 80 and the average code complexity and comments is off as well.

 

Summary:

SourceMonitor is a great way to make sure your code is clean, simple and most importantly – understandable. It is NOT something to be followed as bible but rather a guide.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: