HalsteadMetrics.md (1115B)
1 # Halstead Metrics 2 3 **Source:** [https://en.wikipedia.org/wiki/Halstead_complexity_measures/](https://en.wikipedia.org/wiki/Halstead_complexity_measures/) 4 5 **Definition:** Halstead metrics are a set of simple, measurable, software metrics, intended to be platform and language independent. 6 7 ## Metrics 8 9 We have four basic computed values: 10 11 - $n_1$ := the number of distinct operators 12 - $N_1$ := the total number of operators 13 - $n_2$ := the number of distinct operands 14 - $N_2$ := the total number of operands 15 16 Using these numbers we can compute the following: 17 18 - Program vocabulary 19 - $n_1 + n_2$ 20 - Program length 21 - $N_1 + N_2$ 22 - Calculated estimated program length 23 - $n_1 * \text{log}_2(n_1) + n_2 \* \text{log}_2(n_2)$ 24 - Volume 25 - $N \* \text{log}_2(\text{vocabulary})$ 26 - Difficulty 27 - $D = \frac{n_1}{2} \* \frac{N_2}{n_2}$ 28 - Effort 29 - $E = D \* V$ 30 31 - Difficulty attempts to describe how difficult a program is to understand. 32 - Effort has a translation to coding time using the relation: 33 - $T = \frac{E}{18}$ seconds 34 - Volume has a translation to delivered bugs 35 - $B = \frac{V}{3000}$