2

For a C# project of mine the code metrics delta after a refactoring are:

  • Maintability Index: -4
  • Cyclomatic Complexity: -48
  • Depth of Inheritance: 0
  • Class Coupling: -9
  • Lines of Code: -85

How come the Maintainability Index has decreased when the formula is:

MI = MAX(0,(171 - 5.2 * ln(Halstead Volume) - 0.23 * (Cyclomatic Complexity) - 16.2 * ln(Lines of Code))*100 / 171) ?

Christian
  • 7,433
  • 4
  • 36
  • 61

2 Answers2

2

Possible options: 1) the Halstead volume has increased; 2) you use a MI-variant that takes comments in to account.

Alexander Serebrenik
  • 3,567
  • 2
  • 16
  • 32
  • Can't really verify either option since the code I wrote is no longer with me but since you've pointed out the only two possible options I'll accept the answer. Thanks! – Christian Apr 20 '12 at 21:20
  • 1
    Microsoft's description of the MI as used by Visual Studio uses the formula as provided in the question, i.e., without taking comments into account. – avandeursen Sep 14 '14 at 03:52
1

Not sure if anyone still cares about the answer, but ...

The formula for the Maintainability Index uses the average HV, CC, and LOC. So a possible explanation would be that you removed one or two small classes, which would not be good for the average size, and hence for the MI.

The fact that the MI works with averages is just one of several problems with the Maintainability Index, so you may be better of ignoring it.

avandeursen
  • 8,458
  • 3
  • 41
  • 51