scitools.com

← Metric catalog

Average Code 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 Code Lines

API ID: AvgCountLineCode
Also Known As: Average Method Size (AMS)
Languages: Ada, Basic, C#, C++, Fortran, Java, Jovial, Pascal, Python, Rust, Web
Targets: Classes, Files, Modules, Packages

Average number of lines containing source code 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 1 code line and SayHello::printHello() has 11, so class SayHello's Average Code Lines is Average(1, 11) = 6. The file also includes cyclomaticDemo() (27 code lines) and main() (14 code lines): Average(1, 11, 27, 14) = 13.25, which rounds to 13. func() is declared here but never defined, so it contributes nothing to either average.

See Code Lines for the per-function count this averages, and Average Code Lines (Includes Inactive) to also count inactive code lines before averaging.

Also known as Lorenz & Kidd - Average Method Size (AMS).


Targets By Language: Configuration: