Paritian

Developers

Maintainability Index Calculator (Halstead, Cyclomatic Complexity, Lines of Code)

The maintainability index of a function, class or file from its Halstead volume, cyclomatic complexity and lines of code, on the original scale and on the 0–100 scale used by Visual Studio.

Results

Maintainability index (original scale) 52.7
Maintainability index (0–100, as in Visual Studio) 31
Rating (Visual Studio bands) Good maintainability (20–100)
How it changes
Maintainability index (0–100, as in Visual Studio)Lines of code 10 – 500. Maintainability index (0–100, as in Visual Studio): 54.333 → 17.2717Maintainability index (0–100, as in Visual Studio)0204060100200300400500Lines of code

The dashed line marks the value you entered.

What this tool does

The maintainability index is a single number built from three measurements: MI = 171 − 5.2 ln(V) − 0.23 G − 16.2 ln(LOC), from Oman and Hagemeister's work in the 1990s. The logarithms mean that doubling the lines of code costs about 11 points, while each extra decision path costs a small amount. Visual Studio rescales it to 0–100, flooring at zero, and shows green from 20, yellow from 10 and red below 10. It is a rough guide, useful for spotting the worst outliers in a code base, and it says nothing about whether the code is correct or well designed.

Formula

MI = 171 − 5.2 ln V − 0.23 G − 16.2 ln LOC · Visual Studio index = max(0, MI × 100 ÷ 171) (V = Halstead volume, G = cyclomatic complexity)

Variables

SymbolMeaningUnit
vHalstead volume of the code—
cxCyclomatic complexity—
locLines of code—
MIMaintainability index (original scale)—
VSMaintainability index (0–100, as in Visual Studio)—
RTRating (Visual Studio bands)—

Worked example

  • Halstead volume of the code1500
  • Cyclomatic complexity12
  • Lines of code120
  • Maintainability index (original scale)52.7
  • Maintainability index (0–100, as in Visual Studio)31
  • Rating (Visual Studio bands)Good maintainability (20–100)

Limitations

  • The result is an estimate based only on the values you type. Real situations often include factors this calculator does not know about.
  • The default values are typical reference figures, not measurements of your situation. Replace them with your own data whenever you have it.