Skip to content
SE eBook
Menu

Size Metrics - Lines of Code (LoC)

Public section
Preferences are saved on this device.

One of the oldest and most widely used size metrics is Lines of Code (LOC).

Lines of Code (LOC) measures the size of a software project based on the number of lines of source statements or instructions written in the program. In most definitions, comments, blank lines, and header lines are excluded, and only executable or declarative statements are counted (often called source LOC or SLOC).

For example, consider the following simple function in C:

// compute the sum of two integers
int add(int a, int b) {

    int s = a + b;    // calculate sum
    return s;
}

This snippet has 6 physical lines, but if we exclude the comment and the blank line, only 3 lines (the function header, declaration, and return) are counted as LOC.

Shortcomings of LOC
  • Difficult to estimate early: Estimating LOC from a problem specification is challenging. Accurate LOC values are usually known only after the code has been written, which limits LOC as an early planning tool.
  • Variability in effort: Two modules with the same LOC may require very different effort. Code with complex logic or heavy data manipulation generally takes more effort than simple, straightforward code, even if both have the same number of lines.
  • Programmer variability: Different programmers may express the same functionality in more or fewer lines, depending on their style, experience, and use of language features. This variability can distort LOC-based effort and productivity comparisons.

Despite these limitations, LOC remains a useful and widely collected metric because:

  • It is easy to compute and can be automated by tools.
  • Historical LOC data can support rough effort and cost estimation for future projects that use similar languages, tools, and development practices.
Login to add personal notes and bookmarks.