scitools.com

← Metric catalog

Average Comment Lines 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.

Average Comment Lines

API ID: AvgCountLineComment
Languages: Ada, Basic, C#, C++, Fortran, Java, Jovial, Pascal, Python, Rust, Web
Targets: Classes, Files, Modules, Packages

Average number of lines containing comment for all nested functions or methods.

Only functions and methods that are actually defined (not just declared) directly inside the container count towards the average, and the result rounds to the nearest whole number.

For example:


class SayHello {
public:
  SayHello() {}
  void printHello();
};

void SayHello::printHello() {
  ...
}

void cyclomaticDemo() {
  ...
}

int func();
int main() {
  ...
}

SayHello() has 0 comment lines and SayHello::printHello() has 1, so class SayHello's Average Comment Lines is Average(0, 1) = 0.5, which rounds to 1. The file also includes cyclomaticDemo() and main(), neither of which has any comments: Average(0, 1, 0, 0) = 0.25, which rounds to 0. func() is declared here but never defined, so it contributes nothing to either average.

To also count comments inside inactive regions before averaging, use Average Comment Lines (Includes Inactive). See Comment Lines for the per-function count this averages.


Targets By Language: Configuration: