Main Content

Number of Lines Without Comment

Number of lines of code excluding blank lines and comment-only lines

Description

The number of lines without comment is given by

Number of lines without comment  = NT - (NB + NC),
where:

  • NT is the total number of lines.

  • NB is the number of blank lines.

  • NC is the number of comment-only lines.

Lines of code that contain inline comments are considered executable lines of code and are excluded from NC when calculating this metric.

Polyspace® calculates this metric for source files and header files in the same folders as source files. Use one of these options to specify other behavior:

Examples

expand all

// Function to calculate power
long long power(double x, int n) {
	long long BN = 1;       // long long
	for(int i = 0; i < n; ++i) {
		BN *= x;
	}
	return BN;
}

// Function to calculate approximate index
double AppxIndex(double m, double f) {
	double U = (power(m, 2) - 1) / (power(m, 2) + 2);          //First term
	double V = (power(m, 4) + 27 * power(m, 2) + 38) /
	           (2 * power(m, 2) + 3);                         // Second term
	return (1 + 2 * f * power(U, 2) * (1 + power(m, 2) * U * V +
	                                   power(m, 3) / power(m, 3) * (U - V)))
	       / ((1 - 2 * f * power(U, 2) * (1 + power(m, 2) * U * V
	                                      + power(m, 3) / power(m, 3) * (U - V))));
}

In this example, Polyspace calculates the number of lines without comment by subtracting the number of lines that are comment-only (NB) and blank lines (NB) from the total number of lines (NT) in the source file. Polyspace evaluates the metric as 16. When evaluating this metric, the lines of code that contain inline comments are counted as executable lines of code.

Metric Information

Group: File
Acronym: LINES_WITHOUT_CMT
HIS Metric: No