Visual Studio 2008 Code Metrics
VS 2008 has added a new feature called Code Metrics (CM). Code Metrics is a way to produce actionable information on a project or solution. When you generate CM on your code it produces such things as Maintainability Index, Cyclomatic Complexity, Class Coupling, Inheritance depth and lines of code.
Here is a brief description of each:
Cyclomatic Complexity: How many paths of execution are in your code. i.e. Enter a Method, That’s 1, Hit an If, That’s 2, Hit an Else, That’s 3. This has a Cyclomatic complexity of 3. Here is more robust definition.
Class Coupling: Indicates how many other classes relate to this class
Inheritance depth: The level of inheritance
Lines of code: Self explanatory, everyone’s favorite
Maintainability Index: An aggregate of the above metrics.
Each of these are shown at the assembly level then it allows you to drill down to the namespace, class and method level.
Why is this so cool? Being able to produce and show these metrics allows you to better manage existing code and produce more manageable new code, which in turn pushes you and your team to code to better standards. These metrics are actionable, meaning they enable you to do something with your code by visually displaying the information and giving you the ability to actually assign a work item right from the Code Metrics result window and attach the information to it as well.
This is only one tool in the suite of tools within VS 2008 that will enable and guide you to produce better, more secure and performant code. Harness the power of them all!
The Code Metrics result window; user adding a work item based off metrics:
Work item created from Metrics. Notice the how the work item has all the information attached via the “History” tab.
Ed K.
Originally authored by Ed Kisinger at https://edsquared.com/2007/10/06/Visual+Studio+2008+Code+Metrics.aspx