Adding line numbers is a no-brainer to me. It's frustrating that line numbers aren't included in SO. How many of us code without line numbers? (I sure don't). There simply isn't a better way to refer to an exact location of code (if there was, then compilers would've switched to that method long ago). Especially when making comments (where text length is limited), it would be hugely beneficial to have the option of saying "at line x ..." rather than "where you're dereferencing myVar
for the second time ...", or "In myFunc
, the second call to myFunc2
...", or the code substitution that I see frequently that works like "your broken code here
->my fixed code here
", etc. There are few situations where labeling a location would be more concise than simply referring to a line number.
Now for my counterpoints:
I get error X on line Y, here is my code
Yes, it is true that the line numbers in SO won't match up with the OP's line numbers. So what? 99% of the questions I see like this are syntax errors and they get downvoted and closed as typos anyway. For the remaining 1%, anyone thoughtful enough to be asking a solid question will reference the line numbers that SO provides. If they aren't putting enough effort into their question to do that, then they probably aren't putting enough effort into their question as a whole, and its going to get DVed and closed anyway.
why should it be okay to ask a question with hundreds of lines of
code?
It's not (barring the few instances where this may be necessary for an MCVE). How would adding line numbers encourage this behavior? If somebody does a code dump, it's most likely from an impatient new user who hasn't taken the time read How to Ask and wants an answer right now; the thought of whether or not line numbers will get posted with their code won't even enter their brain. It's not from someone nefariously scratching their chin thinking, "hmmmm, I will make those poor saps on SO eyes' bleed with my line number explosion hahahaha!!!", and then proceed to post 6000 lines of code. Even if they did, it would get ignored/DVed/closed.
Additionally, horizontal space is already somewhat limited in code
blocks, to add line numbers would only make that worse.
Another valid point, but again, there shouldn't/won't be a ton of code posted in the questions. A great majority of Questions will be <100 lines, and certainly the rest will be <1000 lines. If they aren't, they already get ignored/DVed/closed. I can easily live with 2-3 characters of lost horizontal space for the benefit of line numbers; I live with more than that in Vi every day.
I think line numbers should behave in the following ways.
- They only apply to block code, not back-ticked code
- The line numbers scope the entire question. That is, if the OP has a block of code, some text, and another block of code,,, the second block of code starts its numbering where the first left off, not at "1".
- Line numbers only appear after some threshold of lines (10 for instance).
- Best case scenario, SO works some magic and makes them optional, so each user could turn them on or off at will.
For at least the tag I hangout under (c), people generally want to help even if the OP hasn't posted the perfect MCVE-well-researched question. Referencing line numbers is the simplest, most concise way to refer to code, particularly if the OP has multiple bugs in their code.
06
to97
back to08
?#Line:40
. FYI for later readers of this, I will try to keep the link in my profile up-to-date for this script.