Comment Ratio
Ratio of number of lines that contain comments to the total number of lines in a file, expressed as percentage
Description
This metric calculates the ratio of lines containing comments to total number lines in a file, expressed as a percentage.
This metric is equivalent to the Comment Frequency metric defined by European
Cooperation for Space Standardization (ECSS). As defined by EECS, Polyspace® calculates the Comment ratio
metric using this
formula
Comment ratio = 100 * Number of lines containing comments / (Number of code lines without comments + Number of lines containing comments)
int foo() { // Comment line 1 // Comment Line2 // Comment line 3 int x = 0; // Inline comment ignored for comment density but considered for comment ratio return x; }
int foo(){
return x
}
There are four lines containing comment:
// Comment line 1
// Comment line 2
// Comment line 3
int x = 0; // Inline comment ignored for comment density but considered for comment ratio
Polyspace calculates the Comment Frequency as 4/(4+3) × 100%
or
57%
This metric is calculated differently than the Comment Density
metric, which calculates comment density as defined by
the Hersteller Initiative Software (HIS) code complexity standard:
Polyspace calculates the comment density after the preprocessing stage whereas the comment ratio is calculated before preprocessing.
When calculating the comment density, Polyspace counts the three consecutive comments in
foo()
as a single comment. When calculating comment ratio, each line of comment is counted separately.When calculating comment density, Polyspace ignores comments that are appended to lines of code. Such comments are counted when calculating comment ratio.
Examples
Metric Information
Group: File |
Acronym: COMR
|
HIS Metric : No |