Skip to main content
The Halstead metrics are a suite of measures derived purely from the operators and operands in a source file. Maurice Halstead proposed them in Elements of Software Science (1977) as a way to characterize program size, difficulty, effort, and bug count from token statistics alone — without running the code. mehen reports the canonical Halstead suite per space and per file.

What mehen emits

Definitions

The classical Halstead derived quantities follow:
The constant 18 in the time formula is Halstead’s “Stroud number” — the number of mental discriminations per second a programmer is assumed to make.

Per-language operator/operand split

What counts as an operator vs. an operand is language-specific. mehen’s analyzers follow the prevailing convention:
  • Operators: keywords (if, for, return, …), arithmetic and logical symbols (+, &&, …), parentheses pair (), brackets [], and assignment operators.
  • Operands: identifiers, literal values (numbers, strings, booleans, null/undefined), and type names.
The exact mapping for each language lives in its analyzer crate at crates/mehen-<lang>/.

How to read it

halstead.bugs and halstead.time are rough estimates with limited empirical backing. Treat them as order-of-magnitude signals, not promises.

References

  • Halstead, M. H. (1977). Elements of Software Science. Operating and Programming Systems Series. Elsevier. OSTI record.
  • Kearney, J. K., et al. Software Complexity Measurement — MIT lecture notes that summarize the Halstead operator/operand formulation alongside McCabe. PDF (MIT OCW 16.355).
  • Christensen, K., Fitsos, G. P. & Smith, C. P. (1981). A perspective on software science. IBM Systems Journal 20(4): 372–387. DOI.
  • Sonar: Halstead in the metrics definitions.
  • Radon: Halstead — Python reference implementation of the formulas.

See also