The McCabe metrics are a collection of four software metrics:
Cyclomatic Complexity: a.k.a “v(G)”, measures the number of “linearly independent paths”. A set of paths is said to be linearly independent if no path in the set is a linear combination of any other paths in the set through a program’s “flowgraph”. A flowgraph is a directed graph where each node corresponds to a program statement, and each arc indicates the flow of control from one statement to another. “v(G)” is calculated by “v(G) = e - n + 2” where “G” is a program’s flowgraph, “e” is the number of arcs in the flowgraph, and “n” is the number of nodes in the flowgraph. The standard McCabes rules (“v(G)” over 10), are used to identify fault-prone module.
Essential Complexity: a.k.a “ev(G)” is the extent to which a flowgraph can be “reduced” by decomposing all the subflowgraphs of “G” that are “D-structured primes”. Such “D-structured primes” are also sometimes referred to as “proper one-entry one-exit subflowgraphs” (for a more thorough discussion of D-primes, see the Fenton text referenced above). “ev(G)” is calculated using “ev(G)= v(G) - m” where “m” is the number of subflowgraphs of “G” that are D-structured primes.
Design Complexity: a.k.a. “iv(G)”, is the cyclomatic complexity of a module’s reduced flowgraph. The flowgraph, “G”, of a module is reduced to eliminate any complexity which does not influence the interrelationship between design modules. According to McCabe, this complexity measurement reflects the modules calling patterns to its immediate subordinate modules.
Lines of code (LOC): LOC is measured according to McCabe’s line counting conventions.
The Halstead metrics falls into three groups:
Base measures:
Constants set for each function:
For example, the expression “return max(w+x,x+y)” has “N1=4” operators “return, max, +,+)”, “N2=4” operands (w,x,x,y), “mu1=3” unique operators (return, max,+), and “mu2=3” unique operands (w,x,y).
Derived measures:
For notes on defect prediction and the relation of Halstead measures to defect predictors, please refer to our short tutorial on defect prediction here.