Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Measuring the Immeasurable: Code Metrics for Visual Studio

Measuring the Immeasurable: Code Metrics for Visual Studio


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


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.

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

Community comments

  • NDepend

    by Patrick Smacchia,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    You might be interested by NDepend.

    NDepend is a tool for .NET developers that handles more than 60 metrics

    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

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