<p>The scenario here doesn't really give much context for the evaluator's question. Most importantly, we have no information about what she did as a result of the opening question. It is perfectly possible that this opening was a hidden request for context - is the presenter actually familiar with  the code or just doing the PR part of the project? By asking a 'harmless' question which has no right answer, it makes the rest of the questions much easier to pitch.</p>

<p>There is nothing worse when doing an interview than asking an opening question which your student doesn't understand well enough even to be able to guess the answer. </p>

CC BY-SA 3.0
2017-08-26T20:28:40.113Z
2017-08-26T20:28:40.113Z
Sean Houlihane
<p>Unless the student is some kind of an expert already, lines of code will be a easy way to filter out those who have no idea what they are doing. </p>

<p>Lets say the lab manual has about 30 lines for the bubble sort implementation. Leaving out exceptionally talented students, most students would have at least 30 lines, and if they don't they probably haven't written the code. </p>

<p>Its the same concept as in reports. Faculties will ask you to write 2 pages, but what if the content only merits 1 page or 4? Its just another way of valuation. </p>

CC BY-SA 3.0
2017-08-26T09:52:03.767Z
2017-08-26T09:52:03.767Z
Jay
<p><strong>What's the point?</strong></p>

<p>Why does the number of lines in the project matter all that much? Unless the code is <em>extraordinarily long or short</em> (i.e. orders of magnitude away from what is expected), lines of code aren't a good indicator of whether a project is good or bad.</p>

<p>I've heard of one example where some students were set the task of creating a <a href="https://en.wikipedia.org/wiki/Caesar_cipher" rel="noreferrer">Caesar cipher</a><sup>1</sup> program. If you're aware of it, you'll know that it can be trivially solved by using modular arithmetic<sup>2</sup>:</p>



<pre><code>def encrypt(ciphertext, shift):
    output = ''
    for character in ciphertext:
        output += (character + shift) % 26
    return character
</code></pre>

<p>So, the 'smart' solution uses <strong>5 lines</strong>. </p>

<p><strong>One student submitted a solution to that function with 1382 lines.</strong><sup>3</sup></p>

<p><em>Wait, what?</em></p>

<p>I suppose you'd quickly realise that this student's solution was... <em>sub-optimal</em>... if you asked them how many lines when they presented their project.</p>

<p>And here's why:</p>



<pre><code>def encrypt(ciphertext, shift):
    output = ''
    for character in ciphertext:
        if shift == 1:
            if character == 'A':
                output += 'B'
            elif character == 'B':
                output += 'C'
            ...
</code></pre>

<p>So now you can see the merits of using code length to spot solutions that are over 250x longer than necessary.</p>

<p>But when the difference is much smaller, why bother using lines as an indicator of anything? Hopefully, students are <strong>writing clear, maintainable code, not <a href="https://codegolf.stackexchange.com/">playing code golf</a></strong>, so a longer, explicit solution may actually be better.</p>

<p>Equally, treating a higher LoC measurement as a better project is a bad idea. If you do that, you're encouraging unnecessarily verbose solutions, like our student who wrote 1400 lines for a 5 line problem.</p>

<p><strong>Summary</strong></p>

<ul>
<li><p>LoC can be useful for spotting <em>really</em> badly wrong solutions, but setting 'targets' with it can be harmful. </p></li>
<li><p><strong>Asking for the length directly is probably pointless—instead, just take a look at that when you review the code and mark it.</strong></p></li>
</ul>

<hr>

<p><sup>1</sup>You might also know a variant of this as the <a href="https://en.wikipedia.org/wiki/ROT13" rel="noreferrer">ROT13</a> cipher where the shift is 13. This has the convenient property of being self-inverse, so you don't need to subtract to decrypt in a separate function. If our student was really clever and wanted to implement that in Python 2, they could have just written <code>input().encode('rot13')</code>. <a href="https://xkcd.com/353/" rel="noreferrer">It's a whole new world up here!</a></p>

<p><sup>2</sup>There's a bit of a <a href="https://en.wikipedia.org/wiki/Lie-to-children" rel="noreferrer">lie-to-children</a> here, if you're not paying attention. That code assumes that all the letters you want to encode are encoded from 0 to 25 (e.g. 0 = A, 1 = B). That's not how character encodings work in reality (there's an offset in ASCII before you get to the capital letters), but it's not relevant for the example.</p>

<p><sup>3</sup>I cheated and calculated the amount of lines you'd use from that approach, rather than actually writing the whole thing and counting the lines.</p>

CC BY-SA 3.0
2017-08-26T09:54:34.760Z
2017-08-26T10:00:57.413Z
2017-08-26T10:00:57.413Z
Aurora0001
<p>I'm surprised that you didn't ask this teacher why she asked this question and how it fits into her overall evaluation. </p>

<p>I don't think anyone can answer this question without more information. We can speculate on situations in which it might be a good question and we can speculate on situations in which it might be a terrible question, but we can't know unless we know why it was asked. Some of the other answers here provide such speculation. </p>

<p>Moreover, you don't say how accurate the teacher expected the answer to be. And we don't know anything about how the teacher intended to use the answer. </p>

<p>I have, myself, asked students at the beginning of a project to tell me how big their self-defined project will be using various measures. That sounds especially stupid until you know that my only goal was to get them to start to think about estimation, which they had never done. The numbers they gave weren't a goal for the project, but only a source of reflection at the end. So at the end, such a question would be completely natural and expected. And expected to be widely divergent from the earlier estimate, of course, since this was their first attempt. </p>

CC BY-SA 3.0
2017-08-26T11:26:56.680Z
2017-08-26T11:33:40.357Z
2017-08-26T11:33:40.357Z
Buffy
<p>I agree with the other posters here: using num LoC as an indicator is a very poor assessment of the code.</p>

<p>I would ask instead:</p>

<p>1) Does it work</p>

<p>2) Is it readable?</p>

<p>3) Has it followed the correct conventions?  Spacing, layout, indentation etc.</p>

<p>4) is it modular: resusable, logically broken into functions/methods with appropriate names for funcs/methods and variables</p>

<p>5) Is the documentation adequate (docstring/header, method docs, comments only where appropriate)</p>

<p>Less lines of code does not always mean more efficient.</p>

<p>Using regular expressions may be pretty cool, but can make it very difficult to read for anyone that has to do maintenance on the code, or even to understand.</p>

CC BY-SA 3.0
2017-08-26T22:11:16.310Z
regex can be readable. If you break them up. Lots of separate bits that you join together. E.g. `LetterOrUnderscore+LetterOrUnderscoreOrNumber+"*"`
ctrl-alt-delor
CC BY-SA 3.0
2017-08-26T15:59:17.637Z
2017-08-26T15:59:17.637Z
srattigan
<p>As others have noted, the simple lines of code doesn't always have a lot of meaning in terms of the project's quality.  My guess is that the question is primarily intended to catch the outliers, those projects with a lot less or more code than average.</p>

<p>In the programming industry I have noticed an odd trend among certain programmers that go through great lengths to make their code as terse as possible.  Variables are short, each line is crammed with as many instructions as possible, etc. Some constructs such as "comprehensions", streams, lambdas or map/reduce allow you to pack a lot of complexity into a few lines.  This results in code that takes up the minimum of space but is often hard for humans to interpret, as if the programmer forgets that humans look at code as often as computers do.  Programs like this would have far fewer lines of code than average but be of poor quality.</p>

<p>On the other hand, a common mistake made by novice programmers is to write a routine, then copy and paste it and make a few small changes to it.  Sometimes called "copy pasta" this is a poor programming practice because it results in code that is redundant and the same bug can appear in many places in the code.  Restructuring and refactoring code can be tricky and time consuming and when programmers get in a hurry they sometimes just copy paste.  Programs like this would have far more lines of code than average but be of poor quality.</p>

<p>Of course the simple line of code check doesn't catch either of these situations, there are automatic ways of trying to detect code quality but they are much more complex and subjective.</p>

CC BY-SA 4.0
2020-04-12T16:38:06.047Z
The first wrong way sounds a lot like APL, which results in write-only coding.
Scott Rowe
CC BY-SA 4.0
2020-04-10T13:28:19.120Z
2020-04-10T13:28:19.120Z
Uncle Long Hair
<h2>Reason 1 : Because without printing it out you can not weigh it.</h2>

<p>When I was an university, there was a myth that some lazy teachers (I don't know the technical terms for the roles), would weigh your reports, and give a grade base on that. I heard of one student that handed in some work with a load of blank paper attached, and got a good grade.</p>

<h2>Reason 2 : To see how complex it is.</h2>

<p>I remember a story by Michael Jackson, about judging how brilliant some one is. I will include the last 3 paragraphs here.</p>

<blockquote>
  <p>“Terrific,” I mumbled respectfully. I got the picture clearly. Fred
  as Frankenstein, Fred the brilliant creator of the uncontrollable
  monster flowchart. “But what about Jane?” I said. “I thought Jane was
  very good. She picked up the program design ideas very fast.”</p>
  
  <p>“Yes,” said the DP Manager. “Jane came to us with a great reputation.
  We thought she was going to be as brilliant as Fred. But she hasn't
  really proved herself yet. We've given her a few problems that we
  thought were going to be really tough, but when she finished it turned
  out they weren't really difficult at all. Most of them turned out
  pretty simple. She hasn't really proved herself yet — if you see
  what I mean?”</p>
  
  <p>I saw what he meant.</p>
</blockquote>

<h2>Reason 3 : To see how complex it is.</h2>

<p>Over complex code is bad, see in working out the final grade, the number of lines of code, goes some ware in the denominator.</p>

<h2>Reason 4 : Looking for outliers</h2>

<p>This is the only one that would make any sense, but people do a lot of thinks that don't make sense.</p>

<p>Because they knew how many line it should take, and they were looking for statistical outliers. If the line count is way off then it is a sign of a problem.</p>

<h2>Summary</h2>

<p>In any case, I could not count lines of code. Even looking for outliers is throught with dangers.</p>

<p>A few years back, when I was a software engineer. Some one introduced a software metrics tool. It measured Mccabe complexity (various complexities of the code). It was a good tool, and very useful. You could find parts of the code that were un-usual. Often you could find bugs by examining these parts of the code.</p>

<p>One day the head of QA came to me, screaming. He was waving a bit of paper with the results of the tests. It showed that a module, that I had written had a complexity for class dependency that was off the chart. I pointed out that all the other complexity metrics were close to zero. He screamed, "but what about this one". I pointed out, that this class was a factory, it was its job to own this complexity, because it would be worse to have it spread about. I said "if it was spread about, then the metrics would not find it, ..." he interrupted "then spread it about". I continued "... but then the code would be much more complex." -- He looked at me blackly.</p>

<p>We stopped using the tool shortly after that. A shame. It was a good tool. It helped us find bugs. However it did not tell us where the bugs were. It told us what the probably bug density is, if you knew how to read it.</p>

<p>So yes lines of code can be useful, but only as a statistical tool.</p>

CC BY-SA 4.0
2017-08-26T15:22:39.207Z
2020-04-02T21:09:44.293Z
2020-04-02T21:09:44.293Z
ctrl-alt-delor
<h1>Because it is an easy question to start with?</h1>

<p>It only takes seconds to count the LOC in a project. Faster than asking. So the point is not the factual information by itself. </p>

<p>The point is starting an interview with a <em>nervous</em> student, about a <em>project</em> of some size. Not a 20 lines exercise for which an interview with each student is a waste of time.</p>

<p>Question followed by: </p>

<ul>
<li>how many files? </li>
<li>What are the most important ones? </li>
<li>Their responsibilities?</li>
</ul>

<p>and</p>

<ul>
<li>Please show some significant part of the code and explain it to me.</li>
</ul>

CC BY-SA 4.0
2020-04-03T09:08:11.397Z
2020-04-05T07:49:42.530Z
2020-04-05T07:49:42.530Z
Michel Billaud
<p>This question was prompted by observing a faculty member in projects evaluation. Before asking anything else, the very first question she asked from every student was: "<strong><em>How many lines does your code have?</em></strong>"</p>

<p>So I need to know how important this question is and is it really worth asking the nervous students who have just arrived to <strong><em>present</em></strong> their full projects rather than a routine programming assignment?</p>

<p>P.S: While I am neither in favour nor against this question but I have been coding since 2009/10 and my personal experience reminds me that I still don't remember the lines of code for even my own freelancing softwares (even for my thesis program - by don't remembering I mean I even don't remember <em>whether it was 1200 lines or 1800 lines</em>).</p>

CC BY-SA 4.0
2020-03-27T18:12:03.163Z
Maybe she was going on the assumption that the students would need a minimum number of lines of code to solve the problem.  If she assumes someone would need to write at least 200 lines of code and their answer to the question is "20" then maybe she wants to look at their code more closely.  Other than that, I cannot imagine how this question really helps much with anything.
Onorio Catenacci
CC BY-SA 4.0
2020-04-10T16:21:07.377Z
@FailedScientist well, did you ask that faculty member?
Michel Billaud
CC BY-SA 4.0
2020-04-12T16:28:49.263Z
I am reminded of the joke Abraham Lincoln told: "*How long should a man's legs be? Long enough to reach the ground.*" So the answer would be: Lines enough to reach the solution.
Scott Rowe
CC BY-SA 3.0
2017-08-26T20:30:25.503Z
If you can define 'worth asking', this question would be better. I'd hope you remember the difference between 50 LOC and 50k though...
Sean Houlihane
CC BY-SA 3.0
2017-08-26T20:34:14.707Z
Was she asking them to come up with a figure from memory, or did they have a computer with the source code in front of them?
Gilles 'SO- stop being evil'
CC BY-SA 3.0
2017-08-26T22:50:19.290Z
@Gilles She was asking them to answer it precisely to the .. say 673 lines of code and they had a computer with source code in it but this question was asked during project evaluation. Her question was normally: Now come to the code.. Wait a minute! Before opening it, tell me how many lines does it have? and introspection began
Failed Scientist
<project><evaluation>
How many lines does your code have?
# How many lines does your code have?

(Asked by: username_0 on 2017-08-26)

This question was prompted by observing a faculty member in projects evaluation. Before asking anything else, the very first question she asked from every student was: "***How many lines does your code have?***"

So I need to know how important this question is and is it really worth asking the nervous students who have just arrived to ***present*** their full projects rather than a routine programming assignment?

P.S: While I am neither in favour nor against this question but I have been coding since 2009/10 and my personal experience reminds me that I still don't remember the lines of code for even my own freelancing softwares (even for my thesis program - by don't remembering I mean I even don't remember *whether it was 1200 lines or 1800 lines*).

**Tags:** project, evaluation

> **Comments:**
> **username_4**: If you can define 'worth asking', this question would be better. I'd hope you remember the difference between 50 LOC and 50k though...  
> **username_5**: Was she asking them to come up with a figure from memory, or did they have a computer with the source code in front of them?  
> **username_0**: @Gilles She was asking them to answer it precisely to the .. say 673 lines of code and they had a computer with source code in it but this question was asked during project evaluation. Her question was normally: Now come to the code.. Wait a minute! Before opening it, tell me how many lines does it have? and introspection began  
> **username_1**: Maybe she was going on the assumption that the students would need a minimum number of lines of code to solve the problem.  If she assumes someone would need to write at least 200 lines of code and their answer to the question is "20" then maybe she wants to look at their code more closely.  Other than that, I cannot imagine how this question really helps much with anything.  
> **username_2**: @FailedScientist well, did you ask that faculty member?  
> **username_3**: I am reminded of the joke Abraham Lincoln told: "*How long should a man's legs be? Long enough to reach the ground.*" So the answer would be: Lines enough to reach the solution.  

---

## 8 answers

### Answer by username_7 on 2017-08-26. Score: 10 | Accepted answer

What's the point?
Why does the number of lines in the project matter all that much? Unless the code is extraordinarily long or short (i.e. orders of magnitude away from what is expected), lines of code aren't a good indicator of whether a project is good or bad.
I've heard of one example where some students were set the task of creating a Caesar cipher1 program. If you're aware of it, you'll know that it can be trivially solved by using modular arithmetic2:
def encrypt(ciphertext, shift):
    output = ''
    for character in ciphertext:
        output += (character + shift) % 26
    return character

So, the 'smart' solution uses 5 lines. 
One student submitted a solution to that function with 1382 lines.3
Wait, what?
I suppose you'd quickly realise that this student's solution was... sub-optimal... if you asked them how many lines when they presented their project.
And here's why:
def encrypt(ciphertext, shift):
    output = ''
    for character in ciphertext:
        if shift == 1:
            if character == 'A':
                output += 'B'
            elif character == 'B':
                output += 'C'
            ...

So now you can see the merits of using code length to spot solutions that are over 250x longer than necessary.
But when the difference is much smaller, why bother using lines as an indicator of anything? Hopefully, students are writing clear, maintainable code, not playing code golf, so a longer, explicit solution may actually be better.
Equally, treating a higher LoC measurement as a better project is a bad idea. If you do that, you're encouraging unnecessarily verbose solutions, like our student who wrote 1400 lines for a 5 line problem.
Summary

LoC can be useful for spotting really badly wrong solutions, but setting 'targets' with it can be harmful. 
Asking for the length directly is probably pointless—instead, just take a look at that when you review the code and mark it.


1You might also know a variant of this as the ROT13 cipher where the shift is 13. This has the convenient property of being self-inverse, so you don't need to subtract to decrypt in a separate function. If our student was really clever and wanted to implement that in Python 2, they could have just written input().encode('rot13'). It's a whole new world up here!
2There's a bit of a lie-to-children here, if you're not paying attention. That code assumes that all the letters you want to encode are encoded from 0 to 25 (e.g. 0 = A, 1 = B). That's not how character encodings work in reality (there's an offset in ASCII before you get to the capital letters), but it's not relevant for the example.
3I cheated and calculated the amount of lines you'd use from that approach, rather than actually writing the whole thing and counting the lines.


---

### Answer by username_8 on 2017-08-26. Score: 5

I'm surprised that you didn't ask this teacher why she asked this question and how it fits into her overall evaluation.

I don't think anyone can answer this question without more information. We can speculate on situations in which it might be a good question and we can speculate on situations in which it might be a terrible question, but we can't know unless we know why it was asked. Some of the other answers here provide such speculation.

Moreover, you don't say how accurate the teacher expected the answer to be. And we don't know anything about how the teacher intended to use the answer.

I have, myself, asked students at the beginning of a project to tell me how big their self-defined project will be using various measures. That sounds especially stupid until you know that my only goal was to get them to start to think about estimation, which they had never done. The numbers they gave weren't a goal for the project, but only a source of reflection at the end. So at the end, such a question would be completely natural and expected. And expected to be widely divergent from the earlier estimate, of course, since this was their first attempt.


---

### Answer by username_9 on 2017-08-26. Score: 3

I agree with the other posters here: using num LoC as an indicator is a very poor assessment of the code.

I would ask instead:

1) Does it work

2) Is it readable?

3) Has it followed the correct conventions? Spacing, layout, indentation etc.

4) is it modular: resusable, logically broken into functions/methods with appropriate names for funcs/methods and variables

5) Is the documentation adequate (docstring/header, method docs, comments only where appropriate)

Less lines of code does not always mean more efficient.

Using regular expressions may be pretty cool, but can make it very difficult to read for anyone that has to do maintenance on the code, or even to understand.

> **Comments:**
> **username_10**: regex can be readable. If you break them up. Lots of separate bits that you join together. E.g. `LetterOrUnderscore+LetterOrUnderscoreOrNumber+"*"`  

---

### Answer by username_11 on 2020-04-10. Score: 2

As others have noted, the simple lines of code doesn't always have a lot of meaning in terms of the project's quality. My guess is that the question is primarily intended to catch the outliers, those projects with a lot less or more code than average.

In the programming industry I have noticed an odd trend among certain programmers that go through great lengths to make their code as terse as possible. Variables are short, each line is crammed with as many instructions as possible, etc. Some constructs such as "comprehensions", streams, lambdas or map/reduce allow you to pack a lot of complexity into a few lines. This results in code that takes up the minimum of space but is often hard for humans to interpret, as if the programmer forgets that humans look at code as often as computers do. Programs like this would have far fewer lines of code than average but be of poor quality.

On the other hand, a common mistake made by novice programmers is to write a routine, then copy and paste it and make a few small changes to it. Sometimes called "copy pasta" this is a poor programming practice because it results in code that is redundant and the same bug can appear in many places in the code. Restructuring and refactoring code can be tricky and time consuming and when programmers get in a hurry they sometimes just copy paste. Programs like this would have far more lines of code than average but be of poor quality.

Of course the simple line of code check doesn't catch either of these situations, there are automatic ways of trying to detect code quality but they are much more complex and subjective.

> **Comments:**
> **username_3**: The first wrong way sounds a lot like APL, which results in write-only coding.  

---

### Answer by username_10 on 2017-08-26. Score: 2

## Reason 1 : Because without printing it out you can not weigh it.

When I was an university, there was a myth that some lazy teachers (I don't know the technical terms for the roles), would weigh your reports, and give a grade base on that. I heard of one student that handed in some work with a load of blank paper attached, and got a good grade.

## Reason 2 : To see how complex it is.

I remember a story by Michael Jackson, about judging how brilliant some one is. I will include the last 3 paragraphs here.

> “Terrific,” I mumbled respectfully. I got the picture clearly. Fred
> as Frankenstein, Fred the brilliant creator of the uncontrollable
> monster flowchart. “But what about Jane?” I said. “I thought Jane was
> very good. She picked up the program design ideas very fast.”
>
> “Yes,” said the DP Manager. “Jane came to us with a great reputation.
> We thought she was going to be as brilliant as Fred. But she hasn't
> really proved herself yet. We've given her a few problems that we
> thought were going to be really tough, but when she finished it turned
> out they weren't really difficult at all. Most of them turned out
> pretty simple. She hasn't really proved herself yet — if you see
> what I mean?”
>
> I saw what he meant.

## Reason 3 : To see how complex it is.

Over complex code is bad, see in working out the final grade, the number of lines of code, goes some ware in the denominator.

## Reason 4 : Looking for outliers

This is the only one that would make any sense, but people do a lot of thinks that don't make sense.

Because they knew how many line it should take, and they were looking for statistical outliers. If the line count is way off then it is a sign of a problem.

## Summary

In any case, I could not count lines of code. Even looking for outliers is throught with dangers.

A few years back, when I was a software engineer. Some one introduced a software metrics tool. It measured Mccabe complexity (various complexities of the code). It was a good tool, and very useful. You could find parts of the code that were un-usual. Often you could find bugs by examining these parts of the code.

One day the head of QA came to me, screaming. He was waving a bit of paper with the results of the tests. It showed that a module, that I had written had a complexity for class dependency that was off the chart. I pointed out that all the other complexity metrics were close to zero. He screamed, "but what about this one". I pointed out, that this class was a factory, it was its job to own this complexity, because it would be worse to have it spread about. I said "if it was spread about, then the metrics would not find it, ..." he interrupted "then spread it about". I continued "... but then the code would be much more complex." -- He looked at me blackly.

We stopped using the tool shortly after that. A shame. It was a good tool. It helped us find bugs. However it did not tell us where the bugs were. It told us what the probably bug density is, if you knew how to read it.

So yes lines of code can be useful, but only as a statistical tool.


---

### Answer by username_2 on 2020-04-03. Score: 2

# Because it is an easy question to start with?

It only takes seconds to count the LOC in a project. Faster than asking. So the point is not the factual information by itself.

The point is starting an interview with a *nervous* student, about a *project* of some size. Not a 20 lines exercise for which an interview with each student is a waste of time.

Question followed by:

* how many files?
* What are the most important ones?
* Their responsibilities?

and

* Please show some significant part of the code and explain it to me.


---

### Answer by username_4 on 2017-08-26. Score: 1

The scenario here doesn't really give much context for the evaluator's question. Most importantly, we have no information about what she did as a result of the opening question. It is perfectly possible that this opening was a hidden request for context - is the presenter actually familiar with the code or just doing the PR part of the project? By asking a 'harmless' question which has no right answer, it makes the rest of the questions much easier to pitch.

There is nothing worse when doing an interview than asking an opening question which your student doesn't understand well enough even to be able to guess the answer.


---

### Answer by username_6 on 2017-08-26. Score: 1

Unless the student is some kind of an expert already, lines of code will be a easy way to filter out those who have no idea what they are doing.

Lets say the lab manual has about 30 lines for the bubble sort implementation. Leaving out exceptionally talented students, most students would have at least 30 lines, and if they don't they probably haven't written the code.

Its the same concept as in reports. Faculties will ask you to write 2 pages, but what if the content only merits 1 page or 4? Its just another way of valuation.


---

