Software metrics are quantitative measures used to assess the quality, complexity, and effort involved in software development. Halstead metrics are among the most widely studied.
A software metric is a standard of measure used to quantify some property of a software system or its development process. They help predict effort, identify complexity, and improve quality.
Proposed by Maurice Halstead (1977). Based on counts of operators and operands in source code — treats programs mathematically.
| Symbol | Meaning | Example |
|---|---|---|
n1 | Number of distinct operators | +, -, *, =, if, while … |
n2 | Number of distinct operands | variables, constants |
N1 | Total occurrences of operators | sum of all operator uses |
N2 | Total occurrences of operands | sum of all operand uses |
V = N × log₂(n) — N is program length, n is vocabulary size.
D = (n1/2) × (N2/n2)
E = D × V — proportional to both difficulty and volume.
| Count | Value | Items |
|---|---|---|
| n1 (distinct operators) | 3 | int, =, + |
| n2 (distinct operands) | 3 | z, x, y |
| N1 (total operators) | 3 | one each |
| N2 (total operands) | 3 | one each |
| n (vocabulary) | 6 | n1+n2 |
| N (length) | 6 | N1+N2 |
| V (volume) | ≈15.5 | 6 × log₂(6) |
| D (difficulty) | 1.5 | (3/2)×(3/3) |
| E (effort) | ≈23.3 | 1.5 × 15.5 |