Freigeben über


Maintainability Index Range and Meaning

Another question:

The maintainability index has been re-set to lie between 0 and 100. How and why was this done?

The metric originally was calculated as follows: Maintainability Index = 171 - 5.2 * ln(Halstead Volume) - 0.23 * (Cyclomatic Complexity) - 16.2 * ln(Lines of Code)

This meant that it ranged from 171 to an unbounded negative number.  We noticed that as code tended toward 0 it was clearly hard to maintain code and the difference between code at 0 and some negative value was not useful.   I'll post some tech ed sample code showing very low maintainability or you can try on your own code to verify.  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)

On top of that we decided to be conservative with the thresholds.  The desire was that if the index showed red then we would be saying with a high degree of confidence that there was an issue with the code.  This gave us the following thresholds (as mentioned in this blog previously):

For the thresholds we decided to break down this 0-100 range 80-20 so that we kept the noise level low and only flagged code that was really suspicious. We have:

  • 0-9 = Red
  • 10-19 = Yellow
  • 20-100 = Green

Comments

  • Anonymous
    November 21, 2007
    PingBack from http://alvinashcraft.wordpress.com/2007/11/21/daily-dose-of-links-20071121/

  • Anonymous
    November 21, 2007
    Why dont you consider unit testing coverage to be a part of the maintability index? A method can be complex but as long as there are unit tests for it, it is much simpler to maintain.

  • Anonymous
    November 22, 2007
    Time for another weekly round-up of developer news that focuses on .NET, agile and general development

  • Anonymous
    November 27, 2007
    Can you please compare in a few words what's the main difference between the "Analyze" menu, to other 3rd party source code analysis tools (Checkmarx, RATS, LINT, etc...)? Does the analysis engine provide data flow analysis? Is it possible to add custom metrics (locs per funcs ...)? Thanks, Jeff

  • Anonymous
    November 28, 2007
    The comment has been removed

  • Anonymous
    November 29, 2007
    In answer to some of the questions posted: Q: Does the analysis engine provide data flow analysis? A: No, at this time we do not perform true data flow analysis.  We are looking at that for a future version. Q: Is it possible to add custom metrics? A: Not at this time, see http://blogs.msdn.com/fxcop/archive/2007/11/15/code-metrics-customization.aspx

  • Anonymous
    November 29, 2007
    The comment has been removed

  • Anonymous
    December 17, 2007
    Having inherited a lot of code in past lives as a development lead or dev manager, determining code complexity

  • Anonymous
    January 14, 2008
    Чем отличается Visual Studio 2008 Standard Edition от Visual Studio 2008 Professional Edition http://msdn2.microsoft.com/en-us/vs2008/products/bb980920.aspx

  • Anonymous
    August 06, 2008
    Todos tenemos de esas cosas que nos enervan... cuando empieza a llover (y nos mojamos) en un día de sol

  • Anonymous
    August 06, 2008
    Todos tenemos de esas cosas que nos enervan... cuando empieza a llover (y nos mojamos) en un día de sol

  • Anonymous
    September 25, 2008
    Virtual Tech Days day one, session one. I delivered a talk titled "know your tools better".

  • Anonymous
    November 13, 2008
    One of the challenges, I always faced was the availability of approaches for quantification of the aspects

  • Anonymous
    December 08, 2008
    The comment has been removed

  • Anonymous
    February 05, 2009
    [ Nacsa Sándor , 2009. január 19. – február 5.] Ez a Team System változat fejlett eszközrendszert kínál

  • Anonymous
    March 14, 2009
    Voici un article bien détaillé expliquant le fonctionnement de Code Metrics de Visual Studio 2008. Et leur explication de leur calcul de l'indice de maintanibilité basée sur la formule d'Halstead

  • Anonymous
    March 18, 2009
    My first blog entry and it’s just a quick one; I’ve been curious about exactly how the code metrics in