Lines of Code (LOC) Metrics in Software Engineering: Assessing Program Size (with Limitations)

Understand Lines of Code (LOC) as a simple software size metric. This tutorial explains its calculation, limitations (inconsistencies in counting, ignoring complexity), and how it can be used as a basis for other software metrics, providing context for its role and limitations in software project assessment.



Lines of Code (LOC) Metrics in Software Engineering

Introduction to LOC Metrics

Lines of Code (LOC) is a simple metric used to measure the size of a computer program. It's one of the oldest software metrics, often used to assess programmer productivity and to compare projects. While straightforward to calculate, LOC has limitations and is not universally accepted as a comprehensive measure of software size or complexity.

Calculating LOC Metrics

LOC is simply a count of the lines in a program's source code. This includes executable statements, comments, and blank lines. However, inconsistent counting practices across organizations can affect the reliability of LOC as a metric. (Further explanation of the issues in obtaining a consistent measure of LOC would be added here.)

Using LOC for Other Metrics

LOC can be used as a basis for calculating other software metrics:

  • Errors per KLOC (thousands of lines of code).
  • Cost per KLOC.
  • Defects per KLOC.
  • Documentation pages per KLOC.
  • Errors per person-month (PM).
  • Productivity (KLOC/PM).
  • Cost per page of documentation.

Advantages of LOC

  • Simple to calculate and understand.

Disadvantages of LOC

  • Does not measure other aspects of software size (functionality, complexity).
  • Poor code style can lead to inflated LOC.
  • Language-dependent.
  • Difficult for non-programmers to interpret.
  • Not universally accepted as a reliable metric.
  • Does not measure non-code artifacts (requirements specifications, design documents, etc.).