Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

Possible Duplicate:
Why are there no line numbers in the code listings?

Hi, Should not there be line numbers with the code samples in questions and answers? it makes it easier to refer in the description.

share|improve this question

marked as duplicate by random, Jeff Atwood Aug 30 '09 at 9:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I second this request. Line numbers if implemented properly should not make copying code difficult as the other comments seem to suggest. I am sure you have seen plenty of other sites with copy-safe line numbers. google search for "code show line numbers blog" gives… which is pretty copy-safe – abel Oct 2 '10 at 10:31

I'm not so sure... I always find line numbers a distraction; I don't show them when I'm coding, so why would I want them now?

If I want to highlight a code in one of my samples, I add a comment...

var z = x / y; // <==== throws error

If it is the OP's line, I just quote it..., for example: the line "var z = x / y" might throw if y is zero; is this possible with your data?

If this did happen, I wouldn't want to see it on single-line answers - there would be a lot of 1s...

share|improve this answer

Line numbers might make it easier to refer to a specific line. On the other hand, they'd make it much harder to copy stuff off the site and paste it in your editor.

share|improve this answer
Very good point. I do this a lot. – nb69307 Aug 30 '09 at 9:03

As well as all the other points (in particular the "copy/paste" argument), I'd add the following.

Line numbers are useful in longer pieces, where you refer to "line 4: set up the connection, line 5: provide credentials, line 8: set up the query" and so on. However, I've found that the vast majority of StackOverflow questions (certainly ones I'm involved in) don't have such quantities of code in the answer (explanation isn't always needed or given in any longer question's code segments), so any explanation needed is usually given in the text or in comments.

When I'm publishing code segments on sites, and need to provide notes for specific lines, I usually use something like this:

line_of_code();  // 1
final_code();    // 2

This has the benefits that:

  • it's not clogging up the screen for those who don't like seeing line numbers
  • it doesn't bother copy/pasters
  • it's got the annotating benefits; I can say "At line marked 1 above, ..."

The most obvious benefit: we've already got the ability to do this now :)

share|improve this answer

Adding line numbers could help make the answer more understandable, sometimes I wish I could reference a specific line in the code and it's a bit hard without actual line numbers.

I would suggest adding a "copy this" link on top of the code that way we can copy the code without the line numbers.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged .