For a NCLOC size metric to be useful, it is important to adhere to a coding standard. For example, it might be possible to code an if statement in several ways:
| Example | Code | NCLOC |
|---|---|---|
| 1. | if (count > 0)
{
average = sum/count;
}
else
{
average = 0.0;
}
|
8 |
| 2. | if (count > 0) {
average = sum/count;
}
else {
average = 0.0;
}
|
6 |
| 3. | if (count > 0) average = sum/count; else average = 0.0; |
4 |
| 4. | if (count > 0) average = sum/count; else average = 0.0; |
2 |
To get consistent results, you can't mix these styles. While your instructor strongly favors the style of Example 1, the important thing is to adopt a coding standard and stick to it.
This page was last updated on September 16, 1998; send comments to Mark Sebern.