When, if ever, is "line of code" a useful metric?

Some people claim that the code for the worst enemy is its size, and I tend to agree. But every day you keep hearing things like

  • I write blah lines of code in a day.
  • I own x lines of code.
  • Windows is x million lines of code.

Question: When is it useful to use "# lines of code"?

ps: Please note that when such statements are made, the tone is “more is better.”

+41
metrics
Oct 08 '08 at 18:13
source share
45 answers
  • one
  • 2

I would say when you delete the code to make the project work better.

Saying you deleted the "X row count" is impressive. And much more useful than adding lines of code.

+95
08 Oct '08 at 18:14
source share

I am surprised that no one mentioned Dijkstra's famous quote, so here goes:

Today, my point is that if we want to count lines of code, we should not consider them as “lines created”, but as “spent lines”: the existing generally accepted wisdom is so stupid that the book is designed for the wrong side of the book.

A quote from an article entitled " On the Cruelty of Teaching Computer Science Truly ."

+41
Oct 08 '08 at 19:03
source share

This is a terrible metric, but as other people have noted, it gives you a (very) crude idea of ​​the overall complexity of the system. If you compare two projects: A and B and A - 10,000 lines of code, and B - 20,000, this does not tell you much - project B can be overly detailed, or it can be supercompressed.

On the other hand, if one project is 10,000 lines of code and the other is 1,000,000 lines, the second project is much more complex.

Problems with this metric arise when they are used to evaluate the performance or level of contribution to a project. If the programmer "X" writes 2x the number of lines as the programmer "Y", he may or may not contribute more - perhaps "Y" is working on a more complex problem ...

+30
Oct 08 '08 at 18:53
source share

When bragging about friends.

+22
Oct 08 '08 at 18:16
source share

This is useful when loading a line printer so that you know how many pages will be printed in the list of code that you are going to print.;)

+16
Oct 08 '08 at 18:48
source share

There is one special case when I consider it invaluable. When you are in an interview and they tell you that part of your job will be to maintain existing C ++ / Perl / Java / etc. old project. By asking the interviewer how much KLOC is (approximately) involved in the legacy project, it will give you a better idea of ​​whether you want their work or not.

+15
Jan 08 '13 at 4:51
source share

At least not for progress:

"Measuring programming progress along lines of code is similar to measuring aircraft progress by mass." --Bill Gates

+13
Sep 13 '10 at 8:09
source share

like most indicators, they mean very little without context. So the short answer is: never (except for a line printer, this is ridiculous! Who is printing programs these days?)

Example:

Imagine you're testing units and refactoring outdated code. It starts with 50,000 lines of code (50 KLOC) and 1,000 proven errors (failed unit tests). The ratio of 1K / 50KLOC = 1 error per 50 lines of code. Obviously, this is terrible code!

Now, a few iterations later, you have reduced known errors by half (and unknown errors by more than what is most likely) and the code base by five times using exemplary refactoring. Now the ratio is 500/10000 = 1 bug per 20 lines of code. This is apparently even worse!

Depending on what impression you want to make, it can be represented as one or more of the following:

  • 50% less errors
  • five times less code
  • 80% less code
  • 60% worsening error to code ratio

they are all true (assuming I haven't messed up the math), and they all suck to summarize the huge improvement that such refactoring efforts should have accomplished.

+6
Oct 08 '08 at 19:10
source share

Answer: when you can talk about negative lines of code. As in: "Today I deleted 40 extraneous lines of code, and the program still functions the same as before."

+4
Oct 08 '08 at 18:15
source share

There are many different Software Metrics . Lines of code are most commonly used and easiest to understand.

I wonder how often code metric lines correlate with other metrics. Instead of buying a tool that can calculate cyclic complexity to detect code smells, I'm just looking for methods with many lines, and they also have high complexity.

A good example of using lines of code is the metric: Errors on lines of code. This may let you know how many errors you should find in your project. My organization usually has about 20 errors per 1000 lines of code. This means that if we are ready to ship a product with 100,000 lines of code, and our database of errors shows that we have detected 50 errors, then we should probably do some more tests. If we have 20 errors per 1000 lines of code, we are probably approaching the quality that we usually are in.

A bad use case is to measure developer productivity. If you measure developer productivity by lines of code, then people tend to use more lines to deliver less.

+4
Oct 08 '08 at 18:31
source share

Reminds me of this:

This letter is very long, simply because I did not have the leisure to make it shorter.
--Blaise Pascal.

+4
Nov 23 '10 at 14:26
source share

I agree that the total number of lines of code in a project is one way of measuring complexity .

This, of course, is not the only measure of complexity. For example, debugging 100 lines of tangled Perl script is very different from debugging a 5000 line Java project with comment templates.

But without looking at the source, you tend to think that more complex lines of code are more complex, just as you think that a 10 MB source archive is harder than a 15 KB source tarball.

+3
Oct 08 '08 at 18:20
source share

This is useful in many ways.

I don’t remember the exact #, but Microsoft had a webcast, which was mentioned for every X lines of code, on average there are a number of errors. You can accept this statement and use it to provide a basic level for several things.

  • How well a code reviewer works.
  • evaluating the skill level of 2 employees, comparing their error ratio for several projects.

Another thing we're looking at is why there are so many lines? Often, when a new programmer gets stuck in traffic, they simply copy and paste pieces of code instead of creating functions and encapsulating them.




I think I wrote x lines of code per day, this is a terrible measure. It does not take into account the difficulties of the problem, the language you are writing in, etc.

+3
Oct 08 '08 at 18:23
source share

It seems to me that there is a finite limit to how many lines of code I can attribute to the top of my head from any given project. The limit is probably very similar to the average programmer. Therefore, if you know that your project has 2 million lines of code, and your programmers can be sure that they can understand if the error is related to 5K lines of code that they know well, then you know that you need to hire 400 programmers for Your code base is well protected from someone else's memory.

It will also make you think twice about how to quickly grow your code base, and may make you think about refactoring them to make it more understandable.

Note. I made up these numbers.

+3
Oct 08 '08 at 18:24
source share

To paraphrase a quote that I read about 25 years ago,

"The problem with using lines of code as a metric is that it measures the complexity of the solution, not the complexity of the problem."

I believe a quote from David Parnassus in an article in ACM Magazine.

+3
Mar 16 '14 at 15:20
source share

This is a measure of performance as well as complexity. Like all indicators, it must be evaluated with caution. A single indicator is usually not enough for a complete answer.

IE, the 500-line program is not as complex as the 5000 line. Now you need to ask other questions to better view the program ... but now you have a metric.

+2
Oct 08 '08 at 18:15
source share

This is a great indicator for frightening / impressive people. About this, and definitely about the context that I see in all three of these examples.

+2
Oct 08 '08 at 18:15
source share

Lines of code are useful for understanding when you are wondering if the code file is too large. Hmmm ... This file is now 5000 lines of code. Maybe I should reorganize this.

+2
Oct 08 '08 at 20:02
source share

When you need to plan the number of punch cards you need to order.

+2
Dec 04 '08 at 13:35
source share

I wrote 2 blog posts about the pros and cons of counting lines of code (LoC):


How do you calculate the number of lines of code (LOC)? : The idea is to explain that you need to count the logical number of lines of code instead of the physical count. You can use tools like NDepend to do this .


Why is counting lines of code (LOC) useful? : The idea is that LoC should never be used to measure performance, but more so to measure test coverage and evaluate software lifetime.

+2
Dec 18 '08 at 16:44
source share

Institute of Software Engineering Maturity Process Software community profile: 1998 End Update (unfortunately, I could not find a link, unfortunately) discusses a survey of about 800 software developers (or maybe it was stores). The average defect density was 12 defects per 1000 LOC.

If you have an application with 0 defects (it doesn’t really exist, but suppose) and wrote 1000 LOC, on average you can assume that you have just entered 12 defects in the system. If the QA detects 1 or 2 defects and what it is, then they need to do more tests, since there are probably 10 more defects.

+2
Oct 09 '09 at 15:44
source share

When you refactor the code base and can show that you deleted the lines of code and all the regression tests still passed.

+1
Oct 08 '08 at 18:15
source share

The lines of code are not so useful in fact, and if they are used as a metric for management, this leads to the fact that programmers do a lot of refactoring to increase their points. In addition, poor algorithms are not replaced by neat short algorithms, because this results in a negative LOC score that counts against you. Honestly, just don’t work for a company that uses LOC / d as an indicator of productivity, because management clearly has no idea about software development, and therefore you will always be on the back side from day one.

+1
Oct 08 '08 at 18:23
source share

When it is indicated why the changes will last so long.

"Windows is 7 million lines of code, and it takes some time to check all the dependencies ..."

+1
Oct 08 '08 at 18:29
source share

In competitions.

+1
08 Oct '08 at 18:34
source share

When the encoder does not know that you are counting lines of code, and therefore it makes no sense to deliberately add redundant code to the game in the system. And when everyone in the team has the same coding style (therefore, the line has a known average value). And only if you do not have the best measure.

+1
Oct 08 '08 at 18:38
source share

Check out the Wikipedia definition: http://en.wikipedia.org/wiki/Source_lines_of_code

SLOC = 'source lines of code'

These indicators, in which I work, are actually quite a lot of time. There are also various ways of calculating SLOC.

From the wikipedia article:

There are two main types of SLOC measures: physical SLOC and logical SLOC.

Another good resource: http://www.dwheeler.com/sloc/

+1
Oct 08 '08 at 19:09
source share

As already noted by most people, this can be an ambiguous metric, especially if you are comparing people coding in different languages.

5000 Lisp lines! = 5000 C lines

+1
Apr 28 '10 at 0:44
source share

This is a very useful idea when it is related to the number of defects. Defects give you quality code. The least “defects” are the best software; It is almost impossible to remove all defects. In many cases, a single defect can be harmful and fatal.

However, it seems that there is unsafe software.

+1
May 16 '12 at 9:08
source share

When determining the level of effort (LOE). If you put together a proposal and you have roughly the same engineers working on a new project, then you can determine how many engineers will be needed over time.

+1
Mar 07 '14 at 18:26
source share
  • one
  • 2



All Articles