Halstead
Maurice Halstead introduced a suite of source-code complexity measures in his 1977 book "Elements of Software Science" [1]. Halstead's approach treats a program as a sequence of tokens, splitting them into operators (e.g. keywords, punctuation, operator symbols) and operands (e.g. identifiers, literals), then derives length, volume, difficulty, and effort measures from counts of how many are distinct versus how many appear in total.
Halstead Metrics¶
| Name | Symbol | Understand Metric ID |
|---|---|---|
| Distinct Operators | n1 | HalsteadDistinctOperators |
| Distinct Operands | n2 | HalsteadDistinctOperands |
| Total Operators | N1 | HalsteadTotalOperators |
| Total Operands | N2 | HalsteadTotalOperands |
| Vocabulary | n | HalsteadVocabulary |
| Length | N | HalsteadLength |
| Volume | V | HalsteadVol |
| Difficulty | D | HalsteadDifficulty |
| Effort | E | HalsteadEffort |
Notes:
- Vocabulary (n = n1 + n2), Length (N = N1 + N2), Volume (V = N × log₂n), Difficulty (D = (n1 ÷ 2) × (N2 ÷ n2)), and Effort (E = D × V) are all derived from the four base counts above.
- Halstead Maintainability Index also builds on Halstead Volume, but isn't part of Halstead's own suite — it comes from Coleman, Ash, Lowther, and Oman [2], combining Volume with Cyclomatic Complexity and Code Lines, which come from other suites.
References¶
- Halstead, Maurice H. "Elements of Software Science." Elsevier North-Holland, 1977.
- Coleman, Don, Dan Ash, Bruce Lowther, and Paul Oman. "Using Metrics to Evaluate Software System Maintainability." IEEE Computer, vol. 27, no. 8, 1994, pp. 44-49.
Halstead Plugins¶
| Name | Kind |
|---|---|
| Halstead Difficulty (D) | Metric |
| Halstead Distinct Operands (n2) | Metric |
| Halstead Distinct Operators (n1) | Metric |
| Halstead Effort (E) | Metric |
| Halstead Length (N) | Metric |
| Halstead Maintainability Index | Metric |
| Halstead Metrics | Interactive Report |
| Halstead Total Operands (N2) | Metric |
| Halstead Total Operators (N1) | Metric |
| Halstead Vocabulary (n) | Metric |
| Halstead Volume (V) | Metric |