Welcome to MSDN Blogs Sign in | Join | Help

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 (based on the work in Carnegie Mellon University although we modified the Halstead Volume calculation a little since we don't include comments anywhere in our calculation): 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

 

Published Tuesday, November 20, 2007 4:43 PM by conorm

Comments

Wednesday, November 21, 2007 8:20 AM by Daily Dose of Links - 20071121 « Daily Geek Bits

# Daily Dose of Links - 20071121 « Daily Geek Bits

Wednesday, November 21, 2007 9:46 AM by redsolo

# re: Maintainability Index Range and Meaning

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.

Friday, November 23, 2007 12:06 AM by From the software development trenches

# Izindaba #19

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

Tuesday, November 27, 2007 10:20 AM by Jeff

# re: Maintainability Index Range and Meaning

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

Wednesday, November 28, 2007 9:28 AM by Team System News

# VSTS Links - 11/28/2007

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

Thursday, November 29, 2007 2:18 PM by conorm

# re: Maintainability Index Range and Meaning

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

Thursday, November 29, 2007 2:23 PM by conorm

# re: Maintainability Index Range and Meaning

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

Monday, December 17, 2007 4:49 PM by Are you thinking what I'm thinking?

# Determining Code Complexity

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

Tuesday, January 15, 2008 1:48 AM by Віктор Шатохін [MSFT]

# Полезные ссылки 15.01.2007

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

Wednesday, August 06, 2008 8:54 AM by SkunkWorks

# Hay cosas inútiles, cosas totalmente inútiles y Métricas de Código (sobre todo para desarrollo con SharePoint)

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

Wednesday, August 06, 2008 8:55 AM by SkunkWorks

# Hay cosas inútiles, cosas totalmente inútiles y Métricas de Código (sobre todo para desarrollo con SharePoint)

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

New Comments to this post are disabled
 
Page view tracker