BETA

Maintainability index

The maintainability index tries to indicate how hard a program is to maintain by combining a few complexity-relates methods: cyclomatic complexity (which calculates the amount of decision paths), Halstead Volume (amount of operators and operands) and the amount of lines of code
The index is scored from 0 to 100, with 100 being very maintainable.

A very long function can have a very low cyclomatic complexity, but still be very complex because it still does a lot of things. And if one of those is flawed, it can affect everything that follows.

Just look at these metrics for Minify. Even though in terms of cyclomatic complexity, stripWhitespace (circled) scores low, it's still a pretty complex beast (just look at the code!).

Minify complexity metrics

On the other hand, a function with a huge switch statement could have little intelligent content, but a very big cyclomatic complexity.

The maintainability index is a combination of the amount of lines of code and these 2 complexity metrics in an attempt to predict how hard software is to maintain. The exact formula seems arbitrary: it was engineered to match ratings of manual analysis of software in the 80s.

Maintainability index = max(0, (171 - 5.2 * ln(Halstead volume) - 0.23 * (cyclomatic complexity) - 16.2 * ln(lines of code)) * 100 / 171)

A low maintainability index is a clear indicator of worrisome code. If you're going to build something that touches that code, it's likely going to take longer, with a much greater likelihood of bugs. Code with a high maintainability index is in dire need of refactoring.