Click here to Skip to main content
15,878,959 members
Articles / Programming Languages / Visual Basic

Tool: Code Metrics Viewer Extension for Visual Studio

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
22 Aug 2012CPOL3 min read 16.9K   10   1
Keep an eye on your team's software code metrics

If you're a manager or team lead, metrics are probably a big part of your work day. How's the Sprint going? What does our project burndown look like? Do I have enough money left in the budget this quarter for the toolkit the team just requested? How many pizzas do I need to order for the Planning meeting?

I hope you're looking at metrics on your team's software code just about as often as you look at those numbers. One tool that's helped me to do that very efficiently is the Code Metrics Viewer extension for Visual Studio.

So what kind of metrics does this tool collect for you? As the author of the tool puts it, he endeavors to measure "evolvability of a software system, which is an indicator of the inner quality of software". Seems like it would be a good idea to keep an eye on that. Code Metrics Viewer makes this visible through five categories, which I'll briefly explain (technical explanations are available through the links):

  1. Maintainablity Index - In my opinion, this is the most important metric per class. It is a weighted calculation of the other metrics listed below; consider it as the "overall" rating. A score of 20 indicates reasonably maintainable code. However, I suggest you look for at least double that number if not more. The last two major projects I ran (both multi-tenant web applications) averaged a score of 79 across all assemblies. [1]
  2. Cyclomatic Complexity - The number of possible paths through the code, generally determined by logic blocks (IF .. THEN; FOR EACH; DO .. WHILE; SWITCH .. CASE). To me, this is probably a close second in terms of importance; think of this as the number of test cases (read: team cycles) that might be required to properly cover all the possible results / outcomes of the module. 1 is the lowest score; keep this number as low as your business needs allow.
  3. Class Coupling - A count of the number of other classes Class ABC depends on. Look for a score below 25.
  4. Depth of Inheritance - How many other classes are used to make up this class? The more there are, the tougher it can be to follow the flow of the program when modifying or debugging. A score around 3 here is good; above 6 is a warning.
  5. Lines of Code - Completely self-explanatory

This tool is easy to install and use - simply download it and double-click to install. The plug in page I linked to above also contains information on how to run an Analysis on your Solution; read the "How to get it working?" and "Where can I find the Code Metrics Viewer in Visual Studio?" sections on that page and you should be all set. The author has also set up a blog to share some additional tips and tricks for the tool.

If you don't have a metrics tool for your .NET projects, I suggest giving this one a try.

[1] - I ran into an odd situation while writing this article that I need to investigate further. I ran the Metrics Viewer on a small Solution that creates a .exe file. Even though the three main classes, which made up 80% of the codebase, only averaged a 56 Maintainability Index rating, the Solution received an 80. I think this is because there were some very small classes / enums that scored 90-100. My initial assumption is that the overall Maintainability Index rating is an average of all the class-level ratings, and is not weighted like the class-level ratings. In my case, this was confusing, as I had most of my major classes showing the yellow warning signals, but still received a high rating on the whole assembly. I will try to clarify this with the author.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) SPR Consulting
United States United States
Bryan has been solving business problems with software and Agile methodologies for over twelve years. He has experience in all aspects of the software development lifecycle, having directed multiple projects from client initiation through product delivery, deployment, and growth as a team member, manager or independent contributor. Bryan is also a Certified Scrum Master and Manager.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Christian Amado23-Aug-12 6:04
professionalChristian Amado23-Aug-12 6:04 
Nice work!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.