tags:

views:

1367

answers:

14

One of the companies required from it's prospective employee to give the number of lines of code written in the life time in a certain programming language like Java, or C#. Since, most of us have a number of years of experience in different projects in multiple languages and we hardly keep record of this, what would be the best approach to calculate this metrics. I am sure the smart members of stackoverlow.com will have some ideas.

This is a very respected company in its domain and I am sure they have some very good reason to ask this question. But what makes it also difficult to answer is the type of code to consider. Should I only include the difficult algorithm that I implemented or any code I wrote for e.g. a POJO that had 300 properties and whose getters/setters were generated using IDEs!

+2  A: 

It is an interesting metric to ask for considering you could write many many lines of bad code instead of writing just a few smart ones.

I can only assume they are considering more lines to be better than fewer. Would it be better to not plan at all and just start writing code, That would be a great way to write more lines of code, since at least if I do that I usually end up writing everything at least twice.

wonderchook
I'd vote this up for making some very good points - but it doesn't answer his question :p
Dean
Sadly no it doesn't. I thought about writing up another answer with metrics. Since I think there are estimates for daily amount of code.
wonderchook
+12  A: 

The best response to such a question is one of the following:

  • Why do you want to know?
  • What meaning would you attribute to such a number?
  • Is it OK if I just up and leave just about now?

I would seriously question the motives behind anyone asking such a question either of current or prospective employees. It is most likely the same type of company that would start doing code reviews focusing on the number of lines of code you type.

Now, if they argue that the number of lines of code is a measure of the experience of a programmer, then I would definitely leave the interview at that point.

Simple solutions can be found for complex problems, and are typically better than just throw enough lines of code at the problem and it'll sort itself out. Since the number of bugs produced scales linearly and above with the number of statements, I would say that the inverse is probably better, combined with the number of problems they've tackled.

As a test-response, I would ask this:

If in a program I am able to solve problem A, B and C in 1000 lines of code, and another programmer solves the same problems in 500 lines of code, which of us is the best (and the answer would be: not enough information to judge)


Now, if you still want to estimate the number of lines, I would simply start thinking about the projects the person has written, and compare their size with a known quantity. For instance, I have a class library that currently ranges about 130K lines of code, and I've written similar things in Delphi and other languages, plus some sizable application projects, so I would estimate that I have a good 10 million lines of code on my own at least. Is the number meaningful? Not in the slightest.

Lasse V. Karlsen
+1  A: 

Why bother calculating this metric without a good reason? And some random company asking for the metric really isn't a good reason.

If the company's question is actually serious, and you think the interview might lead to something interesting, then I would just pick a random number in order to see where that leads :-)

RoadWarrior
+2  A: 

Smart of stack overflowers would generally avoid organization that ask this kind of question. Unless the correct answer is "huh, wtf??"

Mark Harrison
+3  A: 

There are basically three ways of dealing with ridiculous requests for meaningless metrics.

  1. Refuse to answer, challenging the questioner for their reasons and explaining why those reasons are silly.

  2. Spending time gathering all the information you can, and calculating the answer to the best of your ability.

  3. Making up a plausible answer, and moving on with as little emotional involvement possible in the stupidity as possible.

The first answers I see seem to be taking the first line. Think about whether you still want the job despite the stupidity of their demands. If the answer is still Yes, avoid number 1.

The second method would involve looking at your old code repositories from old projects.

In this case, I would go with the third way.

Multiply the number of years you have worked on a language by 200 work days per year, by 20 lines of code a day, and use that.

If you are claiming more than one language per year, apportion it out between them.

If you have been working more on analysis, design or management, drop the figure by three quarters.

If you have been working in a high-ceremony environment (defence, medicine), drop the figure by an order of magnitude.

If you have been working on an environment with particularly low ceremony, increase it by an order of magnitude.

Then put the stupidity behind you and get on with your life as quickly as possible

Oddthinking
And don't forget to divide the number by your reputation for the period after your StackOverflow registration, to account for the distraction factor. :-)
Oddthinking
+4  A: 

Take a look at ohloh. The site shows metrics from open source projects.

The site estimates that 107,187 lines of code corresponds to an effort of 27 Person Years (4000 lines of code per year).

An example of the silliness of such a metric is that the number is from a project I've been toying with outside work during 2 years.

Cristian Libardo
That's an assembler project, right?
ziggystar
+6  A: 

This seems like one of those questions like 'How many ping-pong balls could you fit in a Boeing 747?' In that case, the questioner wants to see you demonstrate your problem solving skills more than know how many lines of code you've actually written. I would be careful to respond with any criticism of the question, and instead honestly try to solve the problem ; )

Shawn Simon
You can fit 23.782.991 ping pong balls into a Boeing 747. If you open the overhead compartments first, you can fit 25.177.293 of them.
Lasse V. Karlsen
Dude! You are RIGHT! I counted it!
F.D.Castel
Ah, so you're the other one. I was told the numbers had been verified, but not by who. Cool! :)
Lasse V. Karlsen
Is that a european ping pong ball or an african ping pong ball? =]
Ed Woodcock
+3  A: 

Depending on what they do with the answer, I don't think this is a bad question. For example, if a candidate puts JavaScript on their resume, I want to know how much JavaScript have they actually written. I may ask, for example, for the number of lines in the largest JavaScript project they've written. But I'm only looking for a sense of scale, not an actual number. Is it 10, 100, 1000, or 10,000 lines?

When I ask, I'll make very clear that I'm just looking for a crude number to gauge the size of the project. I hope the employer in the questioner's case is after the same.

Ned Batchelder
In that context I would consider it a valid question as well.
Lasse V. Karlsen
A: 

Even if I agree with the majority in saying that this is not a really good metric, if it's a serious compmany, as you say, they may have their reasons to ask this.. This is what I would probably do:

Take one of your existing project, get the number of lines and divide it by the time it took you to code it. This will give you a kind of lines per hour metric. Then, try to estimate how many time you have worked with that specific language and multiply it with your already calculated metric. I honestly don't think it's a great way.. but honest, this isn't a great question neither.. I would also tell the company the strategy I used to come up with this number.. maybe, MAYBE, this is what they want.. to know your opinion about this question and how you would answered it? :p

Or, they just want to know if you have some experiences.. so, guess an impressive number and write it down :D

A: 

"This is a very respected company in its domain and I am sure they have some very good reason to ask this question"

And I am very sure they don't, because "being respected" does not mean "they do everything right", because this is certainly not right, or if it is, then it's at least dumb in my opinion.

What does count as "Lines of Code"? I estimate that I have written around 250.000 Lines of C# Code, possibly a lot more. The Problem? 95% was throwaway code, and not all was for learning. I still find myself writing a small 3-line program for the tenth time simply because it's easier to write those three lines again (and change a parameter) than go search for the existing ones.

Also, the lines of code means nothing. So I have two guys, one has written 20% more Lines that the other one, but those 20% more were unnecessary complicated lines, "loop-unrolling" and otherwise useless stuff that could have been refactored out.

So sorry, respected company or not: Asking for Lines of Code is a sure sign that they have no clue about measuring the efficiency of their programmers, which means they have to rely on stone-age techniques like measuring the LoC that are about as accurate as calendars in stone-age. Which means it's possibly a good place to work in if you like to slack off and inflate your Numbers every once in a while.

Okay, that was more a rant than an answer, but I really see absolutely no good reason for this number whatsoever.

Michael Stum
Wasn't Enron a "very respected company", too? :)
F.D.Castel
Once again wishing I could upvote comments.
wonderchook
A: 

Ha, reminds me when I took over a C based testing framework, which started out as 20K+ lines that I ended up collapsing into 1K LOC by factoring down to a subroutine instead of the 20K lines of diarrea code originally written by the original author. Unfortunately, I got spanked harder for any errors in the code as my KLOC's written actually went negative... I would think long and hard about shrinking the code base in a metrics driven organization....

A: 

If you were to be truly honest then you'd say that you don't know because you have never viewed it as a valid metric. If the interviewer is a reasonable/rational person, then this is the answer they are looking for.

The only other option to saying you don't know is to guess, and that really isn't demonstrating problem solving skills.

A: 

And nobody has yet cited the Bill Atkinson -2000 lines story...

In my Friday afternoon (well, about one Friday per month) self-development exercises at work over the past year, tests, prototypes and infrastructure included, I've probably written about 5 kloc. However one project took an existing 25kloc C/C++ application and reimplemented it as 1100 lines of Erlang, and another took 15kloc of an existing C library and turned it into 1kloc of C++, so the net is severely negative. And the only reason I have those numbers was that I was looking to see how negative.

Steve Gilham
A: 

Sounds like this is D E Shaw's questionnaire?

S I