BT

Measuring the Immeasurable: Code Metrics for Visual Studio

| by Jonathan Allen Follow 576 Followers on May 15, 2007. Estimated reading time: less than one minute |

Code metrics are a way to mathematically calculate the complexity of code. There are several ways to do this, 5 of which are included in Visual Studio Orcas.

The oldest method for calculating code complexity is counting the number of lines in a given function or method. The theory is simply that more lines of code imply more complexity.

Depth of inheritance is the next metric, and perhaps the easiest to understand. Stated plainly, the deeper the inheritance tree the harder it is to understand how changes in a base class may affect its subclasses.

The cyclomatic complexity formula, first developed by Thomas McCabe, is based on the number of branches in a function. Wikipedia lists several versions of the formula, all of which are based on graphing the execution flow through a function.

Maintenance complexity is a calculation based on Halstead metrics.

The final method metric offered is class coupling. It is based on the number of distinct types referenced by the method or class. This should be of particular interest to those trying to achieve loosely coupled systems.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

NDepend by Patrick Smacchia

You might be interested by NDepend.
www.ndepend.com

NDepend is a tool for .NET developers that handles more than 60 metrics
www.ndepend.com/Metrics.aspx

It also provides advanced code visualization (metrics & dependencies),
the possibility to compare different versions of your .NET codebase,
or a language dedicated to query and constraint a .NET codebase.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT