Lines of Code Metrics

[Français][Deutsch]

Measurement of Lines of Code Metrics with Testwell CMT++ and CMTJava (Complexity Measures Tools)

The lines of code measures are the most traditional measures used to quantify software complexity. They are simple, easy to count, and very easy to understand.
They do not, however, take into account the intelligence content and the layout of the code.
CMT++ calculates the following lines-of-code metrics:

  • LOCphy: number of physical lines
  • LOCbl: number of blank lines (a blank line inside a comment block is considered to be a comment line)
  • LOCpro: number of program lines (declarations, definitions, directives, and code)
  • LOCcom: number of comment lines

The following recommendations are given for the lines-of-code measures:

Function length should be 4 to 40 program lines. A function definition contains at least a prototype, one line of code, and a pair of braces, which makes 4 lines.
A function longer than 40 program lines probably implements many functions. Functions containing one selection statement with many branches are an exception to this rule.
Decomposing them into smaler functions often decreases readability.

File length should be 4 to 400 program lines. The smallest entity that may reasonably occupy a whole source file is a function, and the minimum length of a function is 4 lines. Files longer than 400 program lines (10..40 functions) are usually too long to be understood as a whole.

At least 30 percent and at most 75 percent of a file should be comments.
If less than one third of a file is comments the file is either very trivial or poorly explained.
If more than 75% of a file are comments, the file is not a program but a document.
In a well-documented header file percentage of comments may sometimes exceed 75%.

further information about our Complexity Measures Tools:
CMT++ (for C/C++)
CMTJava (for Java)


last updated: 07.03.2005

© 1996-2005 Testwell Oy
CTA++, CTC++, CMT++ and CMTJava are products of Testwell Oy, Tampere (Finland)
all other trademarks of this site are the property of their respective owners.