# 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

1. redsolo says:

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.

2. Time for another weekly round-up of developer news that focuses on .NET, agile and general development

3. Jeff says:

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

4. The Visual Studio Code Analysis Team Blog on Maintainability Index Range and Meaning. Willy-Peter Schaub…

5. conorm says:

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

6. conorm says:

Q: 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.

A: I like the idea of including unit test coverage in a metric although I don’t necessarily buy the idea that code with more tests is more maintainable. Low maintainability suggests high cyclomatic and computational complexity (halstead volume) which means there are a lot of paths and a lot of operators.  If you make a change to that code which requires new tests and changes existing tests then you have to work out what the appropriate changes are, work out what the new tests should cover (and make sure they do), validate that the test results are correct etc.  All of which is more work and more potential for error (including false passes).

7. Having inherited a lot of code in past lives as a development lead or dev manager, determining code complexity

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

9. SkunkWorks says:

Todos tenemos de esas cosas que nos enervan… cuando empieza a llover (y nos mojamos) en un día de sol

10. SkunkWorks says:

Todos tenemos de esas cosas que nos enervan… cuando empieza a llover (y nos mojamos) en un día de sol

11. Virtual Tech Days day one, session one. I delivered a talk titled &quot;know your tools better&quot;.

12. One of the challenges, I always faced was the availability of approaches for quantification of the aspects

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

14. 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

15. My first blog entry and it’s just a quick one; I’ve been curious about exactly how the code metrics in