129
votes

Everybody always says that they can beat the "10 lines per developer per day" from the "Mythical Man Month", and starting a project, I can usually get a couple hundred lines in in a day.

But at my previous employer, all the developers were very sharp, but it was a large project, over a million lines of code, with very onerous certification requirements, and interfacing with other multiple-million line projects. At some point, as an exercise in curiosity, I plotted lines of code in the shipping product in my group (not counting tools we developed), and sure enough, incrementally, it came to around 12 lines net add per developer per day. Not counting changes, test code, or the fact that developers weren't working on the actual project code every day.

How are other people doing? And what sort of requirements do you face (I imagine its a factor)?

6
  • 13
    should be community wiki.
    – Malfist
    Commented Jun 8, 2009 at 20:27
  • 24
    If "10" was in binary it'd be closer to the mark.
    – geofftnz
    Commented Jun 8, 2009 at 20:27
  • 9
    I found this nice quote “Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” in this website [link] (devtopics.com/101-great-computer-programming-quotes)
    – mm24
    Commented May 5, 2012 at 23:24
  • 1
    Count not just the new lines, but the changed/deleted lines too!
    – Aaaaaaaa
    Commented Jul 6, 2012 at 9:46
  • 2
    @Greg Bacon, Bill the Lizard : I would really like this question to be opened again. It may not be exactly fitting SO's rules, but it is definitely attracting visitors. (35875 viewers so far) Commented Apr 15, 2013 at 8:31

15 Answers 15

108
votes

On one of my current projects, in some modules, I am proud to have contributed a negative line count to the code base. Identifying which areas of code have grown unnecessary complexity and can be simplified with a cleaner and clearer design is a useful skill.

Of course some problems are inherently complex and required complex solutions, but on most large projects areas which have had poorly defined or changing requirements tend to have overly complex solutions with a higher number of issues per line.

Given a problem to solve I much prefer the solution that reduces the line count. Of course, at the start of small project I can generate many more than ten lines of code per day, but I tend not to think of the amount of code that I've written, only what it does and how well it does it. I certainly wouldn't aim to beat ten lines per day or consider it an achievement to do so.

1
  • 49
    +1 for contributing negative lines. I once worked on a small project where I shrunk the line count from 15K to 5K while adding new features (and greatly decreasing bug count and increasing speed).
    – rmeador
    Commented Jun 8, 2009 at 22:28
55
votes

I like this quote:

If we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent". - Edsger Dijkstra

Some times you have contributed more by removing code than adding

46
votes

I think the number of lines added is highly dependent upon the state of the project, the rate of adding to a new project will be much higher than the rate of a starting project.

The work is different between the two - at a large project you usually spend most of the time figuring the relationships between the parts, and only a small amount to actually changing/adding. whereas in a new project - you mostly write... until it's big enough and the rate decreases.

2
  • Indeed. Early on in said project the net ad was much larger. Commented Jun 8, 2009 at 22:13
  • 1
    So, it sustains the theory to split a large project to many independent parts (may be even independent projects) - for decoupling.
    – sergzach
    Commented Apr 16, 2013 at 13:40
30
votes

You should stop using this metric, it is meaningless for the most part. Cohesion, coupling and complexity are more important metrics than lines of code.

3
  • 25
    I was not using it as a productivity metric. This was a private exercise for my own curiosity. Commented Jun 8, 2009 at 20:31
  • 3
    Fair enough. Even so it is hard to answer without a more precise definition of what is to be considered a line of code. Commented Jun 8, 2009 at 20:33
  • 1
    @Matthias: I should edit that into the OP if I were you, I for one would have been less... aggressive :P
    – annakata
    Commented Jun 8, 2009 at 20:53
28
votes

How are other people doing?

I am the only full-time dev at our company and have written 500,000 lines of OCaml and F# code over the past 7 years, which equates to about 200 lines of code per day. However, the vast majority of that code is tutorial examples consisting of hundreds of separate projects each a few hundred lines long. Also, there is a lot of duplication between the OCaml and the F#. We are not maintaining any in-house code bases larger than 50kLOC.

In addition to developing and maintaining our own software, I have also consulted for many clients in industry over the past 7 years. For the first client, I wrote 2,000 lines of OCaml over 3 months which is 20 lines of code per day. For the next client, four of us wrote a compiler that generated millions of lines of C/C++/Python/Java/OCaml code as well as documentation in 6 months which is 2,000 lines of code per day per developer. For another client, I replaced 50kLOC of C++ with 6kLOC of F# in 6 months which is -352 lines of code per day. For yet another client, I am rewriting 15kLOC of OCaml in F# which will be the same size so 0 lines of code per day.

For our current client, I will replace 1,600,000 lines of C++ and Mathematica code with ~160kLOC of F# in 1 year (by writing a bespoke compiler) which will be -6,000 lines of code per day. This will be my most successful project to date and will save our client millions of dollars a year in on-going costs. I think everyone should aim to write -6,000 lines of code per day.

7
  • 1
    I like your answer and I understand the sarcasm. Just as curiousity, could you please clarify why rewriting the code in F# will save money to your client? I was familiar with OCaml and did wrote an interpreter in that language and did not touch the language since few years, and now I keep hearing of F# (so I am geniuinely curious about this)
    – mm24
    Commented May 5, 2012 at 23:15
  • 7
    @mm24 "could you please clarify why rewriting the code in F# will save money to your client". Firstly, they got really screwed over by Wolfram Research who charge them £1m consultancy contracts to fix problems they deliberately introduced in Mathematica upgrades, e.g. changing the semantics of [LongDash]. Secondly, they get to consolidate two code bases (Mathematica & C++) that are currently maintained in tandem into one F# code base, reducing not only duplicated effort but many interactions wrt product updates and fixes identified in testing.
    – J D
    Commented May 6, 2012 at 10:00
  • 7
    @mm24 Thirdly, automation. They are doing lots of things by hand for which there are either pre-existing .NET tools to automate or .NET makes it easy to construct such tools. Tasks include instrumenting code with timers to measure performance (use a profiler), writing serializers by hand (use a library), copying key-value names by hand (use reflection) and critical updates to live systems submitted by business are actioned by people in IT by hand (write a tool so business can make changes directly).
    – J D
    Commented May 6, 2012 at 10:07
  • 7
    @mm24 Fourthly, massive performance improvements. F# is orders of magnitude faster than Mathematica and their proof-of-concept code in F# is 5x faster than their production C++ code. This means that tests execute in seconds rather than hours, at which point testing becomes an integral part of development, dramatically improving productivity.
    – J D
    Commented May 6, 2012 at 10:08
  • 7
    @mm24 Fifthly, increased capabilities. They want to do dead code elimination and measure the code coverage of their tests but they cannot do this with the tools they're on. Moving to .NET makes this (and more!) easy.
    – J D
    Commented May 6, 2012 at 10:09
13
votes

Without actually checking my copy of "The Mythical Man-Month" (everybody reading this should really have a copy readily available), there was a chapter in which Brooks looked at productivity by lines written. The interesting point, to him, was not the actual number of lines written per day, but the fact that it seemed to be roughly the same in assembler and in PL/I (I think that was the higher-level language used).

Brooks wasn't about to throw out some sort of arbitrary figure of productivity, but he was working from data on real projects, and for all I can remember they might have been 12 lines/day on the average.

He did point out that productivity could be expected to vary. He said that compilers were three times as hard as application programs, and operating systems three times as hard as compilers. (He seems to have liked using multipliers of three to separate categories.)

I don't know if he appreciated then the individual differences between programmer productivity (although in an order-of-magnitude argument he did postulate a factor of seven difference), but as we know superior productivity isn't just a matter of writing more code, but also writing the right code to do the job.

There's also the question of the environment. Brooks speculated a bit about what would make developers faster or slower. Like lots of people, he questioned whether the current fads (interactive debugging using time-sharing systems) were any better than the old ways (careful preplanning for a two-hour shot using the whole machine).

Given that, I would disregard any actual productivity number he came up with as useless; the continuing value of the book is in the principles and more general lessons that people persist in not learning. (Hey, if everybody had learned them, the book would be of historical interest only, much like all of Freud's arguments that there is something like a subconscious mind.)

1
  • 3
    A thought about different programmer productivity - In my experience, a mediocre programmer will take x times longer to solve a given problem, but also, unfortunately, write x times more code while at it. So by the simple "lines of code per day", the mediocre programmer is just as productive. Commented Jun 8, 2009 at 20:55
11
votes

It's easy to get a couple of hundred lines of code per day. But try to get a couple of hundred quality lines of code per day and it's not so easy. Top that with debugging and going through days with little or no new lines per day and the average will come down rather quickly. I've spent weeks debugging difficult issues and the answer being 1 or 2 lines of code.

4
  • Indeed. But you will hit that scenario more often as the project gets bigger. I have written perfect 10 line programs that had no bugs. Its all a matter of scale. Commented Jun 8, 2009 at 20:34
  • 1
    There aren't programs that have no bugs. Commented Jun 8, 2009 at 21:52
  • 14
    Bah! your grammar has bugs...
    – RAL
    Commented Jun 10, 2009 at 5:50
  • 3
    @DanielMoura Oh, I'd disagree with that... A "hello world" program might not be very useful, but you'd be able to say pretty confidently that it didn't have any bugs :)
    – WendiKidd
    Commented Aug 26, 2012 at 3:31
10
votes

It would be much better to realize that talking of physical lines of code is pretty meaningless. The number of physical Lines of Code (LoC) is so dependent on the coding style that it can vary of an order of magnitude from one developer to another one.

In the .NET world there are a convenient way to count the LoC. Sequence point. A sequence point is a unit of debugging, it is the code portion highlighted in dark-red when putting a break point. With sequence point we can talk of logical LoC, and this metric can be compared across various .NET languages. The logical LoC code metric is supported by most .NET tools including VisualStudio code metric, NDepend or NCover.

For example, here is a 8 LoC method (beginning and ending brackets sequence points are not taken account):

alt text

The production of LoC must be counted in the long term. Some days you'll spit more than 200 LoC, some others days you'll spend 8 hours fixing a bug by not even adding a single LoC. Some days you'll clean dead code and will remove LoC, some days you'll spend all your time refactoring existing code and not adding any new LoC to the total.

Personally, I count a single LoC in my own productivity score only when:

  1. It is covered by unit-tests
  2. it is associated to some sort of code contract (if possible, not all LoC of course can be checked by contracts).

In this condition, my personal score over the last 5 years coding the NDepend tool for .NET developers is an average of 80 physical LoC per day without sacrificing by any mean the code quality. The rhythm is sustained and I don't see it decreased any time soon. All in all, NDepend is a C# code base that currently weights around 115K physical LoC

For those who hates counting LoC (I saw many of them in comments here), I attest that once adequately calibrated, counting LoC is an excellent estimation tool. After coding and measuring dozens of features achieved in my particular context of development, I reached the point where I can estimate precisely the size of any TODO feature in LoC, and the time it'll take me to deliver it to production.

1
  • 1
    Your post is fundamental and deserves far more upvotes. Commented Apr 15, 2013 at 8:33
9
votes

There is no such thing as a silver bullet.

A single metric like that is useless by itself.

For instance, I have my own class library. Currently, the following statistics are true:

Total lines: 252.682
Code lines: 127.323
Comments: 99.538
Empty lines: 25.821

Let's assume I don't write any comments at all, that is, 127.323 lines of code. With your ratio, that code library would take me around 10610 days to write. That's 29 years.

I certainly didn't spend 29 years writing that code, since it's all C#, and C# hasn't been around that long.

Now, you can argue that the code isn't all that good, since obviously I must've surpassed your 12 lines a day metric, and yes, I'll agree to that, but if I'm to bring the timeline down to when 1.0 was released (and I didn't start actually making it until 2.0 was released), which is 2002-02-13, about 2600 days, the average is 48 lines of code a day.

All of those lines of code are good? Heck no. But down to 12 lines of code a day?

Heck no.

Everything depends.

You can have a top notch programmer churning out code in the order of thousands of lines a day, and a medium programmer churning out code in the order of hundreds of lines a day, and the quality is the same.

And yes, there will be bugs.

The total you want is the balance. Amount of code changed, versus the number of bugs found, versus the complexity of the code, versus the hardship of fixing those bugs.

3
  • Amen! (plus spaces to meet 15 char min)
    – Nate
    Commented Jun 8, 2009 at 21:37
  • Note, those statistics were calculated by DPack (usysware.com/dpack). Commented Jun 8, 2009 at 21:39
  • 5
    Perhaps the 10 lines per day rule doesn't apply to something smaller, like the class library you wrote (I assume by yourself). Much of Brooks' numbers come from large projects (IBM's OS360), which is on a fundamentally different scale than your class library. My guess is that Brooks' observation is (frequently) valid for large projects that require many people and significant human communication networking, but invalid for smaller projects.
    – J. Polfer
    Commented Jun 8, 2009 at 22:47
6
votes

Steve McConnell gives an interesting statistic in his book "Software Estimation" (p62 Table 5.2) He distinguish between project types (Avionic, Business, Telco, etc) and project size 10 kLOC, 100 kLOC, 250 kLOC. The numbers are given for each combination in LOC/StaffMonth. E.G. Avionic: 200, 50, 40 Intranet Systems (Internal): 4000, 800, 600 Embedded Systems: 300, 70, 60

Which means: eg. for Avionic 250-kLOC project there are 40 (LOC/Month) / 22 (Days/Month) == <2LOC/day!

1
  • 1
    250 Terra Lines of Code? What's wrong with KLoC?
    – fadedbee
    Commented Mar 8, 2013 at 8:55
4
votes

I think this comes from from the waterfall development days, where the actual development phase of a project could be as little as 20-30% of the total project time. Take the total lines of code and divide by the entire project time and you'll get around 10 lines/day. Divide by just the coding period, and you'll get closer to what people are quoting.

3
votes

Our codebase is about 2.2MLoC for about 150 man-years effort. That makes it about 75 lines of c++ or c# per developer per day, over the whole life of the project.

2
votes

I think project size and the number of developers involved are big factors in this. I'm far above this over my career but I've worked alone all that time so there's no loss to working with other programmers.

1
  • 1
    Small projects help, and so does solitary. I was initially shocked to see that we hit this historical figure, at least incrementally. At the start of said project, my productivity was at least 10x higher. Commented Jun 13, 2009 at 0:24
2
votes

Good planning, good design and good programmers. You get all that togheter and you will not spend 30 minutes to write one line. Yes, all projects require you to stop and plan,think over,discuss, test and debug but at two lines per day every company would need an army to get tetris to work...

Bottom line, if you were working for me at 2 lines per hours, you'd better be getting me a lot of coffes andmassaging my feets so you didn't get fired.

1
vote

One suspects this perennial bit of manager-candy was coined when everything was a sys app written in C because if nothing else the magic number would vary by orders of magnitude depending on the language, scale and nature of the application. And then you have to discount comments and attributes. And ultimately who cares about the number of lines of code written? Are you supposed to be finished when you've reach 10K lines? 100K? So arbitrary.

It's useless.

6
  • How do you describe the size of a project then? Commented Jun 8, 2009 at 20:35
  • 1
    If it's from "The Mythical Man-Month", it predates C by a long ways. In that book, Brooks looked at the idea that programmer output in lines/day is fairly constant despite the language, and surmised that writing in a more expressive language (fewer lines per functionality unit) would result in more productive programmers. He was aware that the number would vary widely (his rule of thumb was that operating systems were about 9 times harder than application programs). Commented Jun 8, 2009 at 20:36
  • 2
    Discrete code units, connectivity points (that is, unit interaction), tiers, classes (in OOP) ... there are about a million ways. KLOCs isn't really a good measure other than as a potential unit of complexity. (EG, "this took 3 weeks to debug because I had to pore through 4 KLOCs to find it!")
    – John Rudy
    Commented Jun 8, 2009 at 20:37
  • 2
    @David: I know where it's from, I can read the question and I've got said book in front on the shelf in front of me right now. Interestingly the first published date also says it's post C by 3 years. My point - clearly badly made - was that it's archaic, and further that the very concept is useless. Hah! It really is biblical.
    – annakata
    Commented Jun 8, 2009 at 20:47
  • Well, we had lots of connectivity points and such. But how do you even count those? When does something become a connectivity point? When does a class matter? Compiled code size is probably a better metric within a given system and language, but it varies across systems. Commented Jun 8, 2009 at 20:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.