.Net Coding metric released

by garren 20. January 2010 07:45

I've finally started my first open source project. In the Agile team I am currently working with, I found I needed a simple metric tool to analyze our code and give some simple code metrics to help the team.

The team was using code coverage as our only metric. Code coverage is a very crude tool to determine the quality of our tests. I wanted some more metrics to help us analyze our code to determine the quality of the code being written. We have as a team set certain standards which must be met for each class being written. Two of these is the lines of code per method and the complexity of the method. I initially looked at Ndepend , which is a fantastic tool, to help us measure these, but Ndepend is more complex then what we required. 

From these humble beginning DrivenMetrics was born. DrivenMetrics is a very simple metrics tool that can analyze an assembly to determine the number of lines in a method and the cyclomatic complexity (number of different branches) of a method.

When I set out to write this library I had some simple goals. I wanted to do TDD, I wanted to use Mono.Cecil to learn a bit about it along with ILasm and I wanted to write a console app with some decent commands like any *nix command line tool. I also wanted a good excuse to use github and get a feel for git and then hopefully eventually be cool like all the other cool kids using github :-)

The library works by using Mono.Cecil to disassemble the a .net assembly and then using Mono.Cecil.Pdb to load all the debugging symbols. The two metrics are then run to analyze the code, the results are then written to an html report. The tool is still very much in its infancy and any help from the greater community would be appreciated. To build the code use rake, I have not used albacore or rake.net as my build library but rather the simple BuildUtils.rb from Jeremy Miller's StoryTeller.

 

I would appreciate any feedback anyone is willing to give. I have a Todo.txt with things I would later like to add to the project. The source code is available on github at: www.github.com/garrensmith/Drivenmetric

 

Comments

1/21/2010 4:42:30 AM #

pingback

Pingback from topsy.com

Twitter Trackbacks for
        
        Garren Smith | .Net Coding metric released
        [drivensoftware.net]
        on Topsy.com

topsy.com |

1/21/2010 7:12:58 AM #

Daniel Marbach

Hello
Congrats! I haven't had time to look detailled in the code. But you might be interested in Peter Hals command line parser:

svn.castleproject.org/.../CommandLineArguments.cs

But what I saw your report generation for HTML is quite hacky. I would rather build an internal DOM (for example an XML DOM with XNode, XElement etc.) and then apply an XSLT tranformation to the DOM which outputs the HTML. Your xslt could even be deployed with the tool so that other persons are able to write their own xslt...

Daniel

Daniel Marbach Switzerland |

1/21/2010 5:52:47 PM #

garren

Hi Daniel

Thanks for the tips, yes the report section is definitely  the weakest section and needs to be improved. I used mono.options http://www.ndesk.org/Options as my command line parser and found it really useful and simple

garren South Africa |

1/22/2010 12:39:13 AM #

Urs Enzler

I'm wondering what you want to achieve with these metrics. How do they help you to write better code?

btw:
If you want to limit the number of lines per method, or parameters passed to it, or complexity then another possibility is to use StyleCop with some custom rules: see here for an example www.planetgeek.ch/.../

Urs Enzler Switzerland |

1/22/2010 11:09:19 PM #

trackback

Social comments and analytics for this post

This post was mentioned on Twitter by GarrenSmith: New post... .Net Coding metric released:
I've finally started my first open source project. In the Agile team I a... http://bit.ly/7mjqtv

uberVU - social comments |

1/27/2010 2:52:28 AM #

Jb Evain

Nice! Good luck with the tool!

Jb Evain France |

1/29/2010 7:31:19 AM #

garren

thanks, and thanks for the great work on Mono.Cecil

garren United States |

9/8/2010 1:05:31 AM #

pingback

Pingback from davechappelle.interactiveinfonet.info

Chappelle dave myspace video - Chappelle comment - Dave chappelle

davechappelle.interactiveinfonet.info |

Comments are closed

About

Garren is a Driven Software professional. He has a strong background in .net programming. His passion for Agile has lead him to work with software teams to help them implement agile methodologies in their workspace. Garren loves learning from the knowledge and experiences of other software professionals and in this blog he shares what he learns in the software world.