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.
Code Lines
| Also Known As | Lines of Code (LOC) Source Lines of Code (SLOC) |
| API ID | CountLineCode |
| Targets | Architectures Classes Files Functions Modules Packages Project Subprograms |
| Languages | Ada Assembly Basic C# C++ Fortran Java Jovial Pascal Python Rust VHDL Web |
| Categories | Lines |
| Cost | Lookup |
| Tags | Project Summary |
Number of lines containing source code.
A line only counts if it is active. Note that a line can contain source and a comment and thus count towards multiple metrics. For classes this is the sum of CountLineCode for the member functions of the class.
For example:
void SayHello::printHello() {
switch (i) {
case 0:
cout << "Hello World" << endl;
case 1:
cout << "HELLO WORLD!" << endl;
default: // a comment here
for (int m = 0; m < j; m++);
cout << "hello world" << endl;
}
#ifdef A_VERY_NICE_VARIABLE
cout << "Inactive Line" << endl; // Inactive
#endif
}
Lines 11-20 and line 26 (12 lines) all contain code. The cout << "Inactive Line" statement inside the #ifdef A_VERY_NICE_VARIABLE block also looks like code, but since A_VERY_NICE_VARIABLE isn't defined it's inactive and doesn't count, leaving CountLineCode = 11.
To also count code lines inside inactive regions, use Code Lines (Includes Inactive). For the per-language breakdown of code lines in web files, see Code Lines (JavaScript) and Code Lines (PHP).
Also known as Lines of Code (LOC); Source Lines of Code (SLOC).
- Ada: Project, File, Type, Entry, Function, Package, Procedure, Protected, Task
- Basic: Project, File, Method, Module, Class
- C#: Project, File, Class, Method
- C++: Project, File, Class, Struct, Union, Function
- Fortran: Project, File, Module, Block Data, Function, Program, Subroutine
- Java: Project, File, Class, Interface, Method
- Jovial: Project, File, Module, Subroutine
- Pascal: Project, File, Class, Interface, Compunit, Function, Procedure
- Python: Project, File, Class, Function
- Rust: Project, File, Function
- VHDL: Project, File, Procedure, Function, Process, Architecture
- Web: Project, File, PHP Class, PHP Interface