Click here to Skip to main content
Click here to Skip to main content

Tagged as

Free Code Metrics for Visual Studio Professional

, 28 Dec 2012
Rate this:
Please Sign up or sign in to vote.
Overview of code metrics tools for teams consisting of developers with different qualification. This set of tools allows to organize code review process in a more efficient way.

Editorial Note

This article appears in the Third Party Product Reviews section. Articles in this section are for the members only and must not be used by tool vendors to promote or advertise products in any way, shape or form. Please report any spam or advertising.

Introduction

Recently my superior requested to report some code metrics from my team. Unfortunately, Visual Studio professional was used by me and team members. This version does not provide ready to use tools for collecting these statistics. TFS server was not used either.

Note: The explanation for metrics are taken from Wikipedia and extension developer's blog. I am not affiliated with any of the tool authors mentioned in the article. All tools are free to use.

Background and Solution

I have reviewed a number of extensions for Visual Studio Professional, and have stopped on the following combination:

Tool to collect characteristics: Visual Studio Code Metrics PowerTool 10.0, by Microsoft Corporation

http://www.microsoft.com/en-us/download/details.aspx?id=9422

This is the command line tool, that analyzes code in your solution code and provides 5 important quantitative characteristics for Project Manager / Team leader.

Maintainability Index

This metric originally is calculated as follows:

Maintainability Index = 171 - 5.2 * ln(Halstead Volume) - 0.23 * 
			(Cyclomatic Complexity) - 16.2 * ln(Lines of Code) 

But for this specific extension, the team decided to adjust this metric, quoting: As a result of the decreasing usefulness of the negative numbers and a desire to keep the metric as clear as possible, we decided to treat all 0 or less indexes as 0 and then re-base the 171 or less range to be from 0 to 100. Thus, the formula we use is:

Maintainability Index = MAX(0,(171 - 5.2 * ln(Halstead Volume) - 0.23 * 
			(Cyclomatic Complexity) - 16.2 * ln(Lines of Code))*100 / 171) 

Cyclomatic Complexity

Cyclomatic complexity (or conditional complexity) is a software metric (measurement). It was developed by Thomas J. McCabe, Sr. in 1976 and is used to indicate the complexity of a program. It directly measures the number of linearly independent paths through a program's source code. The concept, although not the method, is somewhat similar to that of general text complexity measured by the Flesch-Kincaid Readability Test.

Cyclomatic complexity is computed using the control flow graph of the program: the nodes of the graph correspond to indivisible groups of commands of a program, and a directed edge connects two nodes if the second command might be executed immediately after the first command. Cyclomatic complexity may also be applied to individual functions, modules, methods or classes within a program.

Depth of Inheritance

This metrics was designed specifically for object-oriented analysis: Depth of Inheritance. Depth of inheritance, also called depth of inheritance tree (DIT), is defined as “the maximum length from the node to the root of the tree”.

Class Coupling

Basically, class coupling is a measure of how many classes a single class uses. A high number is bad and a low number is generally good with this metric. Class coupling has been shown to be an accurate predictor of software failure and recent studies have shown that an upper-limit value of 9 is the most efficient.

According to the MSDN documentation, class coupling measures the coupling to unique classes through parameters, local variables, return types, method calls, generic or template instantiations, base classes, interface implementations, fields defined on external types, and attribute decoration. Good software design dictates that types and methods should have high cohesion and low coupling. High coupling indicates a design that is difficult to reuse and maintain because of its many interdependencies on other types.

Lines of Code (also called LOC)

According to the documentation, Lines of Code: “Indicates the approximate number of lines in the code. The count is based on the IL code and is therefore not the exact number of lines in the source code file. A very high count might indicate that a type or method is trying to do too much work and should be split up. It might also indicate that the type or method might be hard to maintain.”http://msdn.microsoft.com/en-us/library/bb385914.aspx

Presentation

Now, when we have a free tool to get the desired code metrics, I started to look for visualization tool, to access the information into easy to use form directly in Visual Studio. Fortunately, I was able to locate such a tool, and this free tool is called Code Metrics Viewer. It can be installed by NuGet package manager, and more detailed information on using the plugin can be found on its blog here.

This plugin provides a visual representation of characteristics, as well as provides additional exploration capabilities.

Points of Interest

This is a must have combination of tools for teams consisting of developers with different qualifications. This set of tools allows to organize code review process in a more efficient way.

License

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

Share

About the Author

Vyacheslav Voronenko
Web Developer
Ukraine Ukraine
Web Developer, interested in bleeding age web technologies and projects.
 
Interests: html5, javascript, cloud computing, paas, openshift, asp.net mvc, mongodb, zoo (hadoop & related)
 

Skills: Software Project Management, .NET, XSLT, SQL Server, XML, T-SQL, SQL, JavaScript, jQuery, Requirements Analysis, HTML, MySQL, ASP.NET, Software Design, AJAX, ASP.NET MVC, Web Applications, LINQ, Entity Framework, C#, HTML5, SSRS, Google Closure, HTML5, gaming, Pig, Razor
 

Labs: http://labs.voronenko.info
 
Info: http://www.voronenko.info

Comments and Discussions

 
QuestionSupport for unmanaged C++? PinmemberMartin08153-Jan-13 22:08 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 29 Dec 2012
Article Copyright 2012 by Vyacheslav Voronenko
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid