martes, 21 de agosto de 2012

How many lines of code per day should a good programmer produce?

It depends on the programming language and the ability of the programmer, but in general, really, how many lines of code I must expect from my programmers?

First we must get rid of all the noise. The duplicate lines for example. There are tools to detect and eliminate repeated code.

Sonar for example is an excellent tool for detecting repeated code. Also there is CPD. You can run those with your nightly builds.

So, how many lines I can expect from them?

There is so much noise because even if I remove all the duplicate code, I still end up with some duplicated code. Avoiding duplication is hard.

Also there are bugs. Watts Humphrey, of SEI and CMM fame, mentioned that there on average there is a bug every 10 lines of code. I cannot agree more.

Also there is always the question how we do things. I can use a linked list or a hashmap and those implementation details will for sure give different number of lines of code, different execution speeds, different implementation speeds, and so on. Most of the the time, using more abstraction gives better results, on less amount of code per funcitonality, faster execution speeds and faster time to market.

So instead of measuring lines of code we should be measuring functionality. The problem with functionality is that it is so hard to define, so Microsoft for example defines function point in relation the different languages and therefore they think they can calculate the contribution of a developer by the number of lines they write and divide by the average number of lines required by a function point in that language. 

Really? You gotta be kidding me.

Because we all know that if a programmer is measured by the number of lines he writes he is going to copy and paste like crazy. But he will get the job done.

So if he gest the work done, what is the problem with that?

The code becomes unmantainable. It is repeated so many times that a single bug can get copied twice and the resulting code now has 3 bugs. If my code with has 3 bugs is copied along another code which has 2 bugs, now 5 bugs got converted into 10. If the resulting 10 bugs get copied twice with other code with 6 bugs, the result is 48 bugs. Only by copying 3 times. Imagine how many times you can copy code and now think that the modifying that code also introduces some subtle bugs.

That's why code is so expensive. It is full of bugs. Bugs that are hard to find and correct. So avoid coipying and pasting and reuse the code. Eliminate bugs by reducing the clutter (boilerplate code) and the repeated code.

One person can write between 100 and 3,000 lines of code per day. But measuring that is lying to yourself.

When a project is finished, dead code removed, and repeated code is not taken into account, usually every programmer has provided between 10 and 50 lines of code per day.

The way you get programmer productivity is not by increasing the lines of code per programmer per day. That doesn’t work. The way you get programmer productivity is by eliminating lines of code you have to write.

The line of code that’s the fastest to write, that never breaks, that doesn’t need maintenance, is the line you never had to write.


-- Steve Jobs

Sources: 
1. http://www.crosstalkonline.org/storage/issue-archives/2010/201007/201007-Humphrey.pdf
2. http://www.youtube.com/watch?v=3LEXae1j6EY#t=41m26s