Halstead Difficulty (D) is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.
Halstead Difficulty (D)
| API ID | HalsteadDifficulty |
| Targets | Files Functions |
| Languages | Any |
| Categories | Tokens |
| Cost | Slow |
| Suites | Halstead |
Halstead Difficulty (D) measures how hard a program is to write or understand
It's calculated as:
- n1 = unique operators (HalsteadDistinctOperators)
- n2 = unique operands (HalsteadDistinctOperands)
- N2 = total operands (HalsteadTotalOperands)
- D = (n1 / 2) * (N2 / n2)
See all Halstead metrics.