Related (but different) question: Why are there no line numbers in the code listings?.

Some posters post blocks of code with line numbers. This generally does not make the code any easier to read (especially if it pushes long lines past the end of the box), and makes it substantially more difficult to copy-and-paste the code if someone wants to try it out.

I suggest that the posting software should check for formatted code blocks with line numbers, and suggest (but not require) that the poster should remove them. The message could also suggest adding a comment like /* this is line 42 */ to any lines referred to by error messages.


I'd say this is rare enough that no formal policy is necessary. I think I've seen it only once. I can't say it bothers me much one way or the other. Stack Overflow is not a sausage factory: we don't have to format all posts identically. A certain amount of variety in phrasing and formatting is perfectly acceptable.

  • 1
    I've seen it several times (and I've edited a few such posts to remove unnecessary line numbers, adding comments where needed). I'm not suggesting a formal policy, just a suggestion that's shown when someone posts code with line numbers. – Keith Thompson Oct 27 '12 at 22:06

I agree and disagree.

On code where line numbers are not relevant to the concrete question, the poster should indeed omit them.

But on code where line numbers are relevant to the concrete question, then they should not be auto-removed. Such posts are indeed rare, but I've posted them more than once. I remember having posted them in questions about stacktraces and about 3rd party open source code. The answer would have been confusing and useless when the line numbers were been auto-removed.

  • I did not suggest auto-removing anything. I did, however, suggest that posters should indicate relevant line numbers with comments rather than by numbering every line. – Keith Thompson Oct 27 '12 at 21:22

Can't say I agree. Personally, I've never seen such code on the or where I am most active. Hence, I don't think it's such a common issue that requires developer intervention. (i.e. "Just a warning").

Educate "offending" users to not include line numbers, and add comments. That should be sufficient, especially if you have the edit privilege.

You must log in to answer this question.

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