views:

1497

answers:

11

Ok so last year I participated in a high school curriculum contest thing at a college(I currently attend this college). I actually got 1st in it but was still a bit angry I didn't get every single one right.

The most baffling of questions on there was

How many lines of code does the average programmer write per day?

  • A. 5
  • B. 10
  • C. 25
  • D. 30

Aside from being a subjective question which depended on language and everything else I was more baffled at what they had as the correct answer. 10.

Even on my bad days at my job I touch more than 10 lines of code(either adding, modifying, or deleting) per day. And when I took this test I had only programmed as a hobby where it was common for me to write a few hundred lines for one of my new projects per day. Where are they getting this random number of ten!? Is this published somewhere? A quick googling found me nothing.

A: 

I know I certainly write more than 10 lines per day.

I think my clients would have something to say if it took me 2 weeks to write a 100 line program for them.

Dean Harding
Real development rarely consists of writing small programs from scratch. If you have a 10,000 line app and spend 2 weeks fixing bugs, how many lines will it have afterwards?
Michael Borgwardt
A: 

Ask those who gave the test. :)

http://www.google.no/search?sourceid=chrome&ie=UTF-8&q=average+lines+of+code+per+day gives a lot of results, but I don't see how one could be certain about the average value for all programmers.

Christian Jonassen
A: 

I have heard that the average is more like 15 SLOC. But that includes:

  • Characterization
  • Design
  • The actual Coding
  • Testing
  • Quality Assurance,
  • Refactoring, and
  • Support

among other things.

It's a meaningless metric anyway. All other things being equal, it's better to have less lines of code to perform a particular task, not more.

Jeff Atwood's article about code size contains a survey that suggests that a 10,000 LOC system would require 13.5 staff months. That works out to about 25 lines of code per day. As the project increases in size, this number decreases (i.e. larger projects are less productive, in terms of LOC).

Robert Harvey
How much of that code is generated by your IDE?
Joe Philllips
@d03boy: None, I would imagine. Things like Linq to SQL are akin to using a library.
Robert Harvey
+1  A: 

In my honest opinion I think the question is moot. It depends on too many factors and any of the options can be shown to be valid by plugging in different reasonable values.

One thing is for sure though, the average is definitely less than what one thinks they write per day.

During the initial project development it's much higher, but when you factor into the average the time spent on any of the following it brings the average way down:

  • on maintenance
  • on support
  • on refactoring (may even decrease the amount of time)
  • on bug fixing
  • on learning how to do something, on learning new technology
  • on trying to reproduce a reported problem
  • on internationalization support
  • on planning, design, documentation, etc.
  • on re-implementing broken sections of code

I know of some days for example that I can write hundreds of lines of code, and other days where I will spend 4 hours trying to hunt down a problem only to have the fix be 1 line.

So is it true? It really depends on what phase your project is in. If on maintenance only 10 lines of code may even be considered high. If on initial project development, 10 lines is definitely too low.

For an elite programmer I think all of the values are too low though. If you calculate it not based on a project but based on the sum of all the source code they've written since they started programming. Also is it do they write per day on working days? On days they actually spent programming? On all days of their lives? Does it consider vacation days? ... etc... moot.

Brian R. Bondy
But maintainence, refactoring, line fixing, all of those pretty much include *writing code*.
Blindy
@Blindy: more often it's *changing* or even *deleting* code that is redundant or obsolete.
Michael Borgwardt
I am betting the 10 line average doesn't include generated code either...
Joe Philllips
Yes but you're still at your keyboard typing in those changes, they don't magically happen. As far as I'm concerned, that's as much typing as writing new code is.
Blindy
+7  A: 

Well, there are at least two things to consider:

First, most software developers don't spend all day writing code. They spend much of their time writing documents, fixing bugs, refactoring code, attending meetings, peer reviewing code, designing things, posting answers on Stack Overflow, and doing other non-programming tasks.

Second, some people can write code a lot faster than others, so ten lines per day being an average doesn't mean that everyone writes only ten lines per day.

It also depends on the industry. If you are working on hard real-time, safety critical systems, the amount of code that can be written in a given span of time is much less than if you're developing, say, web applications. With safety critical systems, you have a much more strict and time consuming development process because you have to be certain that you haven't made any mistakes (in a safety-critical system, mistakes can be fatal; literally).

I know that I have ultra-productive weeks where I can hammer out hundreds of lines of C++ code. Then there are weeks like last week where I spent all week tracking down a bug and finally ended up checking in a one-line fix (woohoo!).

James McNellis
You're saying it's normal to spend a week to fix a single bug!? I thought I was alone *sigh of relief*
Earlz
The people with the highest per-day average would be those who use the "copy-paste-modfy" technique of development, so it's not exactly something to strive for.
Michael Borgwardt
@Earlz: it is possible to spend MONTH tracking down a bug caused by single typo (i.e. will be fixed by changing a letter). It all depends on size and quality of code. If you get a code base that has been in development for a few years, has several megabytes of code, you see it first time in your life, and the bug is extremely hard to pinpoint (i.e. it doesn't immediately crash program, etc), then you clearly won't fix it in a few minutes.
SigTerm
A: 

Also something to consider is the difference between 'writing a new line of code', and replacing an existing line of code.

Like most programmers, I access libraries. I rarely touch the code base for most of the libraries I regularly use. What I often do though is change a few values in a component's data structure and compile or refresh in a browser.

That's a mean question, and whatever you answered is incorrect so it shouldn't have been in the test, in my opinion :P

Danjah
+3  A: 

Steve McConnell's book Software Estimation: Demystifying the Black Art goes into this a little bit.

On page 46 (of my edition) he shows a graph of project productivity.

For "small" projects that actually go-live, a typical metric is 3200 lines of code in the final system for each person-year of effort in the project. IIRC, a "small" project is one with up to 20 developers.

Given 2000 hours in a typical working year, and 8 hours in a typical working day, this comes out to 12.8 lines per day, pretty close to the original posters "10 lines per day".

Now, some definitions are important.

Lines: finished lines of production code - code that is actually running in the final system.

Effort: Total system effort - including project initiation and management, requirements gathering and analysis, architecture and design, development, system testing, integration testing, user acceptance testing, performance testing, deployment, transition, documentation and training.

This is for "small" projects - the figure gets worse for medium and large projects.

As you can see, there is a lot more involved than just the time it takes to tap the keyboard and write a line of code.

A couple of last points.

  • I don't know about you, but I know plenty of developers who have been known to have 3200 line weeks, not just 3200 line years.
  • You'd expect the language choice to have an impact on the number of lines of code written - the research I've read indicated that this is not the case. The limiting factor seems to be one of brain capacity, not a technological one. Whether the language is Assembly, C, Java, C#, Haskell, Lisp or whatever, projects seem to average the same.

(I learnt all this a few years ago and brought it all together in a "Smart Code" presentation I gave to the local .NET user group in March 2010.)

Bevan
Then again, I've also had -2000 line weeks, and I count those among my most productive ones, long term.
Michael Borgwardt
So you're saying that the top developers have 52 times the productivity of the average developer? I'll bet they don't have to take support calls.
Robert Harvey
@Robert: I'm saying that it's possible to achieve productivity 52x (even 100x) that of the average, for *a short time*. Maintaining that on a sustained basis is a whole different problem. That said, I believe it's well established, though off topic here, that top-performing developers will produce 100x the output of their less able brethren.
Bevan
@Michael: Me too. Deleting code can be really satisfying - especially if the system ends up *more* functional when you're done.
Bevan
@Robert Harvey - One of the statistics cited in *The Mythical Man-Month* was a study done at IBM that showed a factor of 30 difference in productivity between the best and worst programmers in the sample and a factor of 10 between the best and average.
ConcernedOfTunbridgeWells
A: 

What about the software for jets or space shuttles or mission critical systems? I'm sure there is a lot of testing and documentation that goes into that. Not to mention research. Not all programming jobs strictly involve programming.

For smaller companies they probably involve a lot of tech support type duties.

Joe Philllips
+2  A: 

Here's Jeff citing a book that lists industry averages:

Project Size       Lines of code (per year)
10,000 LOC         2,000 - 25,000
100,000 LOC        1,000 - 20,000
1,000,000 LOC      700 - 10,000
10,000,000 LOC     300 - 5,000

So yes, 10 new high-quality LOC per day is actually pretty good if you're working on a large, established system.

Michael Borgwardt
I often find when working with older code, my net for the day is a negative number of lines. Refactoring code often shortens it...sometimes significantly.
Chad
A: 

That's an impossible question to answer because there are too many variables. Also, if you could answer the question, the answer is actually meaningless.

i.e. What language? How much time per day does the average programmer spend writing code? Writing new code or working on existing code? How well does the programmer understand the software/tools they are working on? Average measured over what time frame? How many hours a day do they work? How much time spent fixing bugs? How many other people are working on the same product at the same time. i.e. team dynamics can make people more productive on one team than on another where they might be working alone. etc...

Ok, so we can make a big generalization about all these and come up with a number. But what does it mean?

e.g. I wrote 10 lines or perfect code today? or, I wrote 5 lines of perfect code and 5 lines of buggy code that'll need to be changed later. Or, I wrote 10 lines of perfect code today. But tomorrow I realize that I don't need that code and instead it can become 1 line of code.

Honestly, LOC measures are pointless. I'm sure there are other measures of productivity that are more meaningful.

Matt H
+6  A: 

On productive days I remove more code than I write.

Quai