Comment to Code Ratio (Includes Comments Before Functions) is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.
Comment to Code Ratio (Includes Comments Before Functions)
API ID: RatioCommentsWithBeforeToCodeLanguages: Any
Targets: Functions
For functions, the comment to code ratio including comments before the function in the commented line count.
Also known as Hersteller Initiative Software (HIS) COMF metric.
For example, the following function has a CountLineComment value of 2 for the single interior comments, but a CountLineCommentWithBefore value of 3 because the comment preceding the function also counts towards the comment lines. So the ratio of comment to code is 2/4 = 0.50 but this metric will be 3/4 = 0.75 (CountLineCode is 4).
// A comment before the function, does not count for CountLineComment
int doSomething()
{
// A comment inside the function, counts for both
return 0; // a comment on a line that is also a code line
}
Note that a line can be both comment and code, like the return statement in the sample. This ratio can be greater than 1. See also CountLineCommentWithBefore.