Home > Microsoft .Net Development Tips > .NET Developer > Visual Studio 2008 code metrics tools will help keep code clean
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

.NET DEVELOPER

Visual Studio 2008 code metrics tools will help keep code clean


Ed Tittel, Contributor
11.10.2008
Rating: -3.25- (out of 5)


.NET Essentials Channel
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


Code metrics are various mathematical and statistical ways to analyze source code and attempt to rank items according to various different yardsticks. Visual Studio 2008 code metrics rate a project's classes, modules, component classes and namespaces using various measurements that attempt to highlight potential sources of trouble.

Below is a brief explanation for each of these metrics. For the maintainability index, a green box indicates an acceptable measurement, a yellow triangle is a warning, and a red box is a trouble indicator; other measurements are expressed numerically. More detail is available at the Visual Studio Code Analysis Team Blog entry, "New for Visual Studio 2008 -- Code Metrics.")

  • Maintainability Index: At member and type levels, this is expressed as a value between 0 and 100 to assess maintainability. For namespaces and assembly level items this is the average of the maintainability index for all constituent types. The index derives from the Halstead Volume (which is based on the number and use of operators and operands), cyclomatic complexity (see below), and lines of code (also below).

    Higher is better than lower for this metric: values of 100-20 get a green box, 10-19 a yellow and 0-9 a red.
     
  • Cyclomatic Complexity: A measure of the total number of paths through a code item. It is calculated by counting the number of decision points or total number of paths traveled through these code constructs: if, switch, do, while, foreach and for. This number also indicates how many unit tests will be needed to achieve complete line coverage.

    Lower values are better than higher ones.
     
  • Depth of Inheritance: At the type level, this value indicates how many types occur above the type being measured in the inheritance tree. At the namespace and project level, this value identifies the highest depth of inheritance for all constituent types.

    Higher values can indicate over-engineered implementations that may increase test and maintenance complexity.
     
  • Class Coupling: Indicates the number of other classes upon which an item depends, excluding primitives and built-in types (String, Object, Int32).

    The higher the value, the more likely it is that the item will be affected by changes in those other classes. Low values at the type level, by contrast, indicates potential candidates for code reuse.
     
  • Lines of Code: Total number of executable lines of code, excluding white space, comments, braces, declarations of members, types and ...

    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



    RELATED CONTENT
    .NET Developer
    How to speed up Visual Studio 2008's slow WPF designer
    How to list fonts in WPF using markup extensions and data templates
    How to convince management to buy Microsoft Visual Studio 2008
    Microsoft webcast series previews new Visual Studio 2010 features
    New features in Windows 7 bring new UI considerations for developers
    User Account Control (UAC): How to develop code for standard users
    Introduction to Vista's user account control (UAC) for developers
    Downloadable MSDN library released for VS 2008 SP 1
    Widgetbox provides good example of how to use Facebook Developer Toolkit
    Microsoft previews new features in Visual Studio 2010

    .NET Framework 3.5 and Visual Studio 2008 development
    Microsoft's message at TechEd: make the most of what you have
    How to speed up Visual Studio 2008's slow WPF designer
    How to list fonts in WPF using markup extensions and data templates
    How to convince management to buy Microsoft Visual Studio 2008
    Moonlight 1.0 release brings Silverlight to Linux
    Microsoft cuts Visual Studio 2008 upgrade prices as VS 2010 looms
    User Account Control (UAC): How to develop code for standard users
    How to write installers in Vista that work correctly under UAC
    How to elevate programs' privileges correctly using Vista's UAC
    Introduction to Vista's user account control (UAC) for developers

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    Cosmos  (SearchWinDevelopment.com)
    IronRuby  (SearchWinDevelopment.com)
    Visual Studio Express (VSE)  (SearchWinDevelopment.com)

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary


    namespaces themselves. Though a crude measure, it is reasonably predictive of complexity.

    Lower counts are better than higher ones.


To generate Visual Studio 2008 code metrics, start from Solution Explorer, then right-click a solution or project and select Generate Code Metrics from the resulting pop-up menu. That's all there is to it! Working with these metrics helps to improve code readability, reusability, reliability and maintainability. What more could you want? Stay tuned, and I'll let you know in future tips!

Ed Tittel is a full-time writer and trainer whose interests include XML and development topics, along with IT Certification and information security topics. E-mail Ed with comments, questions, or suggested topics or tools to review.


Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts