On this page:
Lab 9 Description
Code Quality
Measures of code quality
Version: 5.2.1

Lab 9

Lab 9 Description

Code Quality

There is no work to be done here - this is just a short write-up on the examples we have shown you in the lecture.

Programs are written to be read by others, (and, by the way, they run on computers). How can we measure whether a program is well written, whether it is readable, well tested?

When the program is well written it does not contain convoluted complicated code that is hard to understand. That means that the programmer, to the best of their ability, followed our one task — one method rule. When the program is structured that way, it is easy to design tests for all helper methods and make sure that all possible paths through the program are covered by tests. Tools that measure test coverage verify this. We do not have such tools - yet.

Other measure of code quality is based on the analysis of the source code, looking at the complexity of possible paths through the program. We will use one such tool in this lab.

The Metrics tool is designed as a plugin for Eclipse. It is installed on our lab machines - you should select the variant of Eclise with Metrics.

The programmer can select to compute the code quality metrics for a specific project and the Metrics plugin will examine the source code and provide a comprehensive report.

Measures of code quality

Some of the values the Metrics computes are the following values. In most cases it reports the maximum, the average, and allows you to see the values for every class in your project.

We find the last one to be the most revealing piece of information for our student’s code. It measures the complexity of the most poorly designed method and will hone in on it. The complexity of the method increases with the addition of each new path through the code that needs to be tested. We will not explain the details here, but will show examples of code where the index value exceeds 10. What we see is that these methods are very complex and nearly impossible to test.

We encourage you to read more about the McCabe Cyclomatic Complexity, think about the code quality, and use tools like this to pinpoint the problems in student code.