Using Software Metrics to Evaluate Complexity and Maintainability

Generally, software that is smaller and less complex contains fewer bugs and is easier to maintain than large, more complex software. Several software metrics have been developed to measure complexity and ease of maintenance quantitatively. Although the overall suitability and applicability of such measures remains an area of active research in the software engineering community, I believe that a limited and targeted use of these measures can give useful feedback on the quality of the code you write in this class.

We will be using the pmccabe package for this purpose. I have created a script compscore.pl which will compute the following three complexity measures:

  1. Average McCabe Complexity: The McCabe complexity counts the number of independent paths through a function. For instance, a function containing no loops and no if or switch statements has a McCabe complexity of 1. Each conditional control flow statement, or use of the tertiary operator ?:, increases this count by 1. A smaller average is better.

  2. Total Number of Statements: This measure counts the total number of C statements by summing up all statements contained in a file's functions, plus adding 1 for each function itself and each global declaration. A smaller total number of statements is better.

  3. Average Number of Statements per Function: For this average, only statements inside functions are considered. A smaller average is better.

In addition, the number of functions will be reported. For instance, running compscore.pl for my own, fully functional implementation of project 0 shows
> compscore.pl memalloc.c
NumberOfFunctions 9 AverageMcCabeComplexity 2.00 TotalStatements 68 AverageStatementsPerFunction 6.33
(This implementation includes an implementation of the optional function mem_dump_freelist)

Both the compscore.pl script and the pmccabe programs are in your path if you included ~cs3204/bin.

The following empirical CDF plots show how the distribution of these measures in student submissions in a past offering of CS 3204:
After you have implemented all required functionality and pass the tests, examine your code for opportunities to reduce each of these measures.