Click here to Skip to main content
13,556,681 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 28 Dec 2012
Licenced CPOL

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.


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

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.”


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.


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


About the Author

Vyacheslav Voronenko
Web Developer
Ukraine Ukraine
Web Developer, interested in bleeding age web technologies and projects.

Experienced and interested in:
- High load web projects, bespoke software development
- DevOps: Chef, Ansible, Vagrant
- NoSQL (mongodb)
- Client stack (javascript core, jquery, AngularJS, HTML5 apis)
- *AAS (Amazon beanstalk, Redhat openshift)
- MEAN & Pure JS stack (Javascript, AngularJS, Node.JS, MongoDB)

-> DevOps inquiries
-> Other inquiries
-> Follow me on Github

You may also be interested in...


Comments and Discussions

QuestionYou mention how you changed the Maintainability Index? Pin
TheEdge29-Feb-15 23:16
memberTheEdge29-Feb-15 23:16 
QuestionSupport for unmanaged C++? Pin
Martin08153-Jan-13 22:08
memberMartin08153-Jan-13 22:08 

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.

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