Saturday, November 16, 2024
Google search engine
HomeGuest BlogsLines of Code (LOC) in Software Engineering

Lines of Code (LOC) in Software Engineering

A line of code (LOC) is any line of text in a code that is not a comment or blank line, and also header lines, in any case of the number of statements or fragments of statements on the line. LOC clearly consists of all lines containing the declaration of any variable, and executable and non-executable statements. As Lines of Code (LOC) only counts the volume of code, you can only use it to compare or estimate projects that use the same language and are coded using the same coding standards. 

Features :

  • Variations such as “source lines of code”, are used to set out a codebase.
  • LOC is frequently used in some kinds of arguments.
  • They are used in assessing a project’s performance or efficiency.

Advantages :

  • Most used metric in cost estimation.
  • Its alternates have many problems as compared to this metric.
  • It is very easy in estimating the efforts.

Disadvantages : 

  • Very difficult to estimate the LOC of the final program from the problem specification.
  • It correlates poorly with quality and efficiency of code.
  • It doesn’t consider complexity.

Research has shown a rough correlation between LOC and the overall cost and length of developing a project/ product in Software Development, and between LOC and the number of defects. This means the lower your LOC measurement is, the better off you probably are in the development of your product.

Let’s take an example and check how does the Line of code work in the simple sorting program given below:

C++




void selSort(int x[], int n) {
  //Below function sorts an array in ascending order
   int i, j, min, temp;
   for (i = 0; i < n - 1; i++) {
      min = i;
      for (j = i + 1; j < n; j++)
      if (x[j] < x[min])
      min = j;
      temp = x[i];
      x[i] = x[min];
      x[min] = temp;
   }
}


So, now If LOC is simply a count of the number of lines then the above function shown contains 13 lines of code (LOC). But when comments and blank lines are ignored, the function shown above contains 12 lines of code (LOC).

Let’s take another example and check how does the Line of code work the given below:

C++




void main()
{
    int fN, sN, tN;
    cout << "Enter the 2 integers: ";
    cin >> fN >> sN;
    // sum of two numbers in stored in variable sum
    sum = fN + sN;
    // Prints sum
    cout << fN << " + " <<  sN << " = " << sum;    
    return 0;
}


Here also, If LOC is simply a count of the numbers of lines then the above function shown contains 11 lines of code (LOC). But when comments and blank lines are ignored, the function shown above contains 9 lines of code (LOC).

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments