McCabe Metrics

One of the early developers of software metrics was T. McCabe, who wrote a seminal paper that identified a software complexity measure [10.25]. Since that time, the field has blossomed, but the metrics developed by McCabe's company have been plentiful and very well received by industry and government.

The desired characteristics of a complexity measure, according to McCabe, are as follows [10.26]:

• It should be closely related to the amount of work it takes to test or validate a program.

• It should conform to our intuitive notion of complexity.

• It should be straightforward for programmers to calculate the complexity measure.

• It would be useful if the measure could be automated.

• It should be objective; different people should get the same complexity for the same program.

• It should be language-independent.

• It should apply to structured and unstructured code.

• It should map into an operational step and actually drive the test effort.

The centerpiece of McCabe's original idea satisfying these characteristics is the notion of software cyclomatic complexity. Cyclomatic complexity is a measure of the logical complexity of a software module and of the minimum effort required to qualify that module. It is the number of linearly independent paths and, as such, represents the minimum number of paths that one should test.

To illustrate the cyclomatic complexity metric, we refer to Figure 10.2, which shows three representations of the logical code, or flowgraph, of a module. Cyclomatic complexity can be calculated using the formula:

Image rights not available

Figure 10.2. Illustration of cyclomatic complexity [10.26].

where CC = cyclomatic complexity

E = number of edges or connections of the code N = number of nodes in the code

Thus, cyclomatic complexity is easy to compute and, in fact, has been automated by McCabe & Associates and is available as a software metrics tool. We note the significance of this metric in terms of identifying testing effort and paths for testing.

McCabe has gone considerably beyond the original complexity measure as described before, producing a variety of metrics as well as software packages that compute these metrics. As a further example, essential complexity measures the extent to which a module contains unstructured constructs. The procedure is that all structured constructs are removed, and then the cyclom-atic complexity of the reduced flowgraph represents the essential complexity. Essential complexity has the advantages of

• Quantifying the degree of structuredness

• Revealing the quality of the code

• Predicting the maintenance effort

• Helping in the modularization process

In addition to the preceding, McCabe has produced a variety of software metrics that measure various aspects of software, including the following tools:

• The Battlemap Analysis Tool™

• The McCabe Instrumentation Tool™

The reader with a further interest in McCabe metrics should contact McCabe & Associates directly (see [10.26] in the References). They are a leading purveyor, both nationally and internationally, of automated tools that compute software metrics.