Chinh Do

A New Way to Measure Lines of Code

23rd August 2007

A New Way to Measure Lines of Code

posted in Programming |

Is Lines of Code a good way to measure programmer output?


First, some background: several studies (Sackman, Erikson, and Grant – 1968; Curtis – 1981) have shown that there are large variations in productivity levels among the best and worst programmers. While the numbers from the studies are controversial, I tend to agree with the basic premise that a super programmer can significantly outperform the average programmer. In my real-world projects, I estimate that variations have ranged up to 5/1.

As a manager or technical lead of a project, it’s important to have a good idea of how productive your programmers are. With a good idea of productivity levels, you can make better estimates for time and resources, and you can manage the individual developers better. Knowing that Programmer A has relatively lower productivity than his teammates, you can assign him smaller features and save the more complex ones for more productive/better programmers. Or, in the case of the negative-productivity programmer, you can identify him quickly and react appropriately instead of letting him continue to negatively impact your project.

So, is Lines of Code (LOC) per Day by itself a good way to measure productivity? I think the answer is a resounding no for many reasons:

  • A good programmer is able to implement the same feature with much less code than the average programmer.
  • Code quality is not taken into account. If you can write a thousand lines of code more than the average programmer, but your code is twice as buggy, that’s not really desirable.
  • Deleting and changing code, activities that are associated with important tasks such as re-factoring and bug-fixing, are not counted, or even counted negatively.

A New Method to Measure LOC

If LOC is not a good way to measure productivity, why am I writing about it? Because it’s still a good metric to have at your disposal, if you use it correctly, carefully, and in conjunction with other data. I also propose a revised method to calculate LOC that can better correlate with productivity. This “new-and-improved” LOC, in conjunction with other data (such as a Tech Lead’s intimate knowledge of his programmers’ style, efficiency, and skill level), may allow us to gain a better picture of programmer productivity.

The traditional way of calculating LOC has always been to count the lines of source code added. There are variations, such as not counting comments or counting statements instead of lines, but the general concept is the same: only lines or statements of code that are added are counted. The problems with the old method are:

  • Buggy code counts as much as correct code.
  • Deleting or changing code is not counted. Deleting/changing code is often done when you are re-factoring, or fixing bugs.
  • Optimizing a 20,000-line module to make it 10,000 lines actually impacts the LOC negatively.

At a conceptual level, my new method to calculate LOC (let’s call it “Lines of Correct Code” or LOCC) only counts correct lines of code, and code that is deleted or changed. Short of reviewing each line of code manually, how does a program know if a line of code is correct? My answer: if it remains in the code base at the end of the produce cycle, then for our purpose, it is “correct” code.

Algorithm for Counting Lines of Correct Code

Below is the proposed algorithm for calculating the LOCC. It should be possible to automate every of the steps described here using a modern source control system.

  • Analyze the source code at the end of the product cycle and keep a picture of the code that exists at the end. This is our base-line “correct” code.
  • Go back to the beginning of the project cycle and examine each check-in. For each check-in, count the lines of code that is added or changed and remains until the end. Lines of code that are deleted are also counted.
  • Auto-generated code is not counted or is weighted appropriately (after all, some work is involved).
  • Duplicate files are only counted once. In many applications, some files are mirrored (shared in SourceSafe-speak) in multiple locations. It’s only fair to count these files only once.

Ways to Use Lines of Correct Code

Here are a few ways I am planning to use LOCC in my projects:

  • Look at the LOCC per day (week/month) of the same developer over time.
  • Compare the LOCC per day between different programmers of equal efficiency and skill level.
  • Compare the total LOCC between different projects to get an idea of their relative size.
  • Correlate the LOCC of a programmer against his/her bug rate.
  • If a programmer writes code that is often deleted or changed later on, try to find out why.

Tell me what you think. Is this LOCC metric something that you would consider using in your project? I am writing a utility to calculate LOCC automatically from SourceSafe and if there’s sufficient interest, I will consider making it available.

This entry was posted on Thursday, August 23rd, 2007 at 4:20 pm and is filed under Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

There are currently 4 responses to “A New Way to Measure Lines of Code”

  1. 1 On April 10th, 2013, Chinh Do said:

    Hi, my blog runs on the WordPress platform. I started out with a WordPress template and made several customizations to it.

  2. 2 On December 23rd, 2015, Emmanuela said:

    می‌گه:سلام!من در هنگام آپلود عکس توو وردپرس (چه فلش و چه معمولی) پیغام خطای زیر رو میگیرم (بعد از اینکه این قالب رو گذاشتم.)Warning: realpath() [function.realpath]: SAFE MODE Restriction in eefcft. The script whose uid is 712 is not allowed to access / owned by uid 0 in /home/googerdc/public_html/wp-includes/functions.php on line 1332Warning: is_dir() []: open_basedir restriction in eefcft. File(/) is not within the allowed path(s): (/home/googerdc:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp) in /home/googerdc/public_html/wp-includes/functions.php on line 1311Warning: file_exists() [function.file-exists]: open_basedir restriction in eefcft. File(/) is not within the allowed path(s): (/home/googerdc:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp) in /home/googerdc/public_html/wp-includes/functions.php on line 1302Warning: is_dir() []: open_basedir restriction in eefcft. File(/) is not within the allowed path(s): (/home/googerdc:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp) in /home/googerdc/public_html/wp-includes/functions.php on line 1311لغو “logo.png” به‌خاطر وجود خطایی بارگذاری نشدامکان ایجاد شاخه /2012/09 نیست. آیا شاخه مادر آن با سرور قابل نوشتن است؟مشکل چیه و چجوری حل میشه؟

  3. 3 On June 21st, 2016, said:

    Bin ja nur Hobbyknipser – aber bei mir geht es genau in die andere Richtung.Smarte Umhängetasche die nicht nach Fototasche aussieht. Eine D7000 + 2 Objektive (Meist das 85er + UWW) und fertig. Das iPad noch. Mehr muss nicht sein!

  4. 4 On June 24th, 2016, said:

    Hi would you mind letting me know which hosting company you’re utilizing? I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a lot faster then most. Can you suggest a good hosting provider at a reasonable price? Many thanks, I appreciate it!

Leave a Comment

  • Calendar

  • August 2007
    M T W T F S S
    « Apr   Sep »