This metric combines Halstead Volume (information content and program size), Cyclomatic Complexity (control flow paths), and Lines of Code (physical size) into a single 0-100 score. Higher scores indicate more maintainable code.
Stellarion uses the standard Microsoft-normalized formula:
MI = MAX(0, (171 - 5.2×ln(HV) - 0.23×CC - 16.2×ln(LOC)) × 100/171)
Components:
The formula normalizes to 0-100, with Halstead Volume weighted at 5.2×ln(HV), Cyclomatic Complexity at 0.23×CC, and Lines of Code at 16.2×ln(LOC). The physical size (LOC component) has the strongest influence on the final score.
Stellarion classifies maintainability using these thresholds:
| Score | Rating | Color | Maintainability Level |
|---|---|---|---|
| 80-100 | Excellent | Green | Highly maintainable |
| 50-79 | Good | Green | Good maintainability |
| 20-49 | Fair | Yellow | Moderate maintainability |
| 10-19 | Poor | Red | Difficult to maintain |
| 0-9 | Poor | Red | Very difficult to maintain |
This metric serves as a leading indicator for:
Development Velocity: Code with low MI slows development. Teams spend more time understanding, debugging, and carefully modifying complex code.
Technical Debt: MI below 50 indicates accumulating technical debt. Each change becomes riskier and more expensive.
Onboarding Efficiency: New team members struggle with low-MI codebases. High MI correlates with faster onboarding and knowledge transfer.
Defect Probability: Studies show strong correlation between low MI and defect density. Poor maintainability leads to more bugs.
Since MI is a composite metric, improvements target its components:
1. Reduce Cyclomatic Complexity (Primary Driver)
The CC component has the most direct impact:
2. Decrease Lines of Code
Reduce function and file length:
3. Simplify Halstead Volume
Reduce operator and operand variety:
Stellarion recommends these refactoring targets based on current MI:
| Current MI | Target MI | Effort Level |
|---|---|---|
| 0-19 | 50+ | High (16+ hours per file) |
| 20-49 | 60+ | Medium (4-16 hours per file) |
| 50-79 | 80+ | Low (1-4 hours per file) |
Consider a file with:
MI = MAX(0, (171 - 5.2×ln(2000) - 0.23×25 - 16.2×ln(400)) × 100/171)
MI = MAX(0, (171 - 39.5 - 5.75 - 97.1) × 0.585)
MI = MAX(0, 28.65 × 0.585)
MI = 16.8 (Poor)
After refactoring to reduce CC to 10 and splitting into smaller files (150 LOC each):
MI = MAX(0, (171 - 39.5 - 2.3 - 81.2) × 0.585)
MI = 48 × 0.585 = 28.1 (Fair)
Further improvements to reduce Halstead Volume would push MI into the Good range.
For the complete metrics reference, see Stellarion Quality Metrics.
Cyclomatic Complexity
Cyclomatic complexity (CC) measures the number of linearly independent paths through a program's source code. Developed by Thomas McCabe in 1976, it remains one of the most widely used metrics for assessing code testability and maintainability.
Circular Dependencies
Circular dependencies occur when two or more modules depend on each other, creating a cycle in the dependency graph. Module A imports Module B, which imports Module C, which imports Module A—forming a closed loop that can cause build failures, runtime errors, and architectural decay.