Code Quality LOC

Audio Version Of This Article

Lines of Code (LoC)

There are several metrics you can deploy to analyze the code size and quality of an application. One of the popular metrics that you can be used is called Lines of Code, also known as LoC. If you are keen to learn more about what LoC means and why it is metric is programming, this article is for you.

What Does LoC Mean?

Lines of Code or LoC is a method used to measure the size of an application by identifying the actual count of Lines of Code it has. For instance, small software projects usually have somewhere between 500 to 5000 Lines of Code, whereas large ones can have thousands or even millions of Lines of Code (LoC).

Purpose of LoC

Estimating the size of a project:

Usually, the size of a software project can be estimated based on the lines of code it has. It is one of the metrics clients can use to determine how much they can pay for a particular software project.

Check size and readability of code units:

Any software project will always have code units like classes and functions. Usually, the functions and classes that have several code lines tend to be harder to read or understand than those. So, it is usually best to split up such classes or functions to make them smaller for easy understanding and readability.

To determine the quality of code:

LoC is among the most reliable parameters that are used to assess the quality of a software program. You will often realize that most experienced developers usually write less code than amateurs even when the project they are working on is the same.

It measures how efficient the language used to code:

An efficient language requires writing less code to accomplish a task that would need to write several lines of code if written in another language that is less efficient.

Methods Used to Measure LoC

There are two common methods used to measure this parameter that is; physical and logical methods. Here is how the two defer

1. Physical Lines of Code:

With this method, the lines of code are physically counted while
excluding comments and white spaces.

2. Logical Lines of Code:

This method measures only the number of executable statements in the code.

Let us use an example below to differentiate between these two;

for (i = 0; i< 100; i++)
{
printf("hello");
}

In this illustration above this code, the segment has four physical lines of code and two logical ones. The logical lines of code are; the for statement and the print statement.

Pros and Cons of Using This Method

Pros

  • It is easy and intuitive
  • Ubiquitous metric
  • Integrated into most code editors

Cons

  • Not a reliable metric to measure a programmer's productivity
  • The LoC also differ based on the experience of a developer
  • The LoC will also vary based on the programming language used

It does not have a counting standard.

Don't Measure Productivity Based on Line of Code

One of the mistakes that clients and some project supervisors who are not familiar with programming make is using LoC as a metric to measure a programmer's productivity. However, using this metric will not give the right picture because the time spent coding usually varies based on how complex the project is and the experience of the programmer.

Conclusion

This parameter is crucial when it comes to assessing the size and quality of software or code segments. However, it would be misleading to use this parameter to measure a programmer's productivity or the progress of a particular project.

Using LoC alone to measure these two parameters is misleading because different project segments vary in complexity and take different amounts of time to accomplish, so the number of LoC written usually doesn't matter.

Updated on September 6, 2021