Halstead complexity metric is a software metric indroduced by Maurice Howard Halstead in 1977. This metric is computed statically, without program execution.
Calculation
First we need to compute the following numbers, given the program:
- = the number of distinct operators
- = the number of distinct operands
- = the total number of operators
- = the total number of operands
From these numbers, five measures are derived:
- Program length:
- Program vocabulary:
- Volume:
- Difficulty :
- Effort:
- Number of the used different operators (( ) and operand ( ), ), together the vocabulary size .
- Number of the altogether used operators ( ) and operand ( ), together the implementation length .
From this then the sizes of Halstead length become ( ) and Healstead volume ( ) are calculated:
From the base quantities one can compute different characteristic numbers, e.g.:
Where D = difficulty of the program to write or understand, e.g. when doing code review.
From http://www.sei.cmu.edu/str/descriptions/halstead.html [1] and the German wikipedia entry.