41

Seems totally backward to me that such an excellent IDE would hide line numbers by default. This seems like an obvious oversight, or poor default.

Which means I'm missing something – because in the VS dev team vs Me, I know who has more experience.

So what am I missing? Why would I not need to see line numbers in code?

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
nailitdown
  • 7,868
  • 11
  • 36
  • 37
  • 3
    I'll give you a +1. This has baffled me in a few IDEs... I mean, it might make more sense in VS which has a good debugger where you can just click and it'll take you to the culprit line, but when working with PHP or something in other IDEs, where it just spits out a line number at you and you actually have to find it... line numbers are very useful. – mpen Nov 12 '09 at 07:31
  • So, it seems what I was missing was familiarity with the IDE... I'm used to working in simpler environments, where line numbers are much more important. From what everyone has raised here, there really is no compelling reason to show them in VS. – nailitdown Nov 12 '09 at 08:01
  • 1
    @Mark: You don't need to be able to click to get to the right line. Almost every editor I've used has a "go to line number X" facility even if it doesn't show line numbers down the side. Surely it's easier to type the line number in than scroll up and down looking for it. – Jon Skeet Nov 12 '09 at 09:27
  • This [ux.se answer](https://ux.stackexchange.com/a/81093/5493) gives another explanation of why are line numbers *not* on by default. – Ozair Kafray Mar 17 '22 at 10:52

10 Answers10

21

Line numbers are essential when pair programming. When two people are working together, it is very helpful to say something to the effect of "There is an issue on line 35"

Mike Valenty
  • 8,941
  • 2
  • 30
  • 32
  • I can understand "useful" in this case, but really "essential"? I've certainly pair programmed without ever talking about line numbers. I'll usually say "in method XXX" or "when you do XYZ you're not doing ABC" - or just point at the screen. – Jon Skeet Nov 12 '09 at 09:26
  • 3
    Only essential if you don't like fingerprints on your screen or armpits in your face when your coworkers is reaching to point something out :) – Mike Valenty Nov 12 '09 at 17:31
  • 3
    It's a lot easier to say "Line 167" than: "Jay S Config dot Date Handler" – seFausto Nov 26 '13 at 18:44
16

The only time I'm interested in line numbers is when I've given a specific one (e.g. in a stack trace). At that point I want to go to that particular line (which I can do directly) but I don't need to see the surrounding line numbers.

I value the contents of my screen, and line numbers would just be wasting it for me.

I think the bigger question is to ask yourself why you would want to see line numbers. Why are they important to you? In what situations do you need to see all the line numbers for the current page, rather than just the current line (which is displayed in the status bar)?

EDIT: I agree with Michael's answer that for the specific example of pair programming, they're useful. Personally I don't happen to pair very often (I'm happy to do so, it's just rare) and so line numbers are not useful - and are even distracting - for the rest of the time.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 3
    Agreed. Ctrl + G is the perfect solution to the stack trace situation. – Jeff Wilcox Nov 12 '09 at 07:21
  • @Anacrolix: Care to give more details? What kind of handholding is relevant here? Could you give an example of a language where it's more important to display line numbers (other than when they're used as labels of course)? – Jon Skeet Nov 12 '09 at 08:26
  • Languages that require special instrumentation for debugging purposes, particularly due to lack of virtual machine abstractions (C/C++/Bash), and more than a single target execution environment (Python). Under such conditions, one can't make assumptions about whether or not the programmer's environment will prettify execution state, such as jumping to the corresponding SLOC and displaying a visual call stack. – Matt Joiner Nov 12 '09 at 09:44
  • 2
    @Anacrolix: That doesn't feel like it's a feature of the *language* though - it's a feature of the *tool*. And as such, I've seen far more editors which support "jump to line" (which even *Notepad* supports) than support line numbers. Why would an editor which *does* support "jump to line" need to also support displaying all line numbers - or rather, how would such an ability compensate for other tools *not* supporting those features? – Jon Skeet Nov 12 '09 at 10:51
  • I often use line numbers to jump around the file even when I haven't been given an error or something with a line number. For example I may want to jump to a particular loop and since the line numbers are showing I'll happen to remember about where I want to go. In vi I sometimes use marks, though that requires that I set one ahead of time rather than just that I notice the numbers while reading. – bames53 Oct 07 '13 at 19:53
  • Let's say I am hollering to my buddy: "hey I found it, it's there on line ###" ... that's why – MetaGuru Dec 11 '13 at 21:20
  • 2
    @ioSamurai: So use the line number part of the status bar, which shows the number of the line you're on. Or does this happen *so* often to you that you really can't afford the time to get your cursor on the right line? – Jon Skeet Dec 11 '13 at 21:24
  • @JonSkeet oh snap, touché – MetaGuru Dec 11 '13 at 21:56
  • @Spencer: For pair programming, I'd agree. All the rest of the time, they're just a distraction. Note that during code review I work in an environment which *does* have them, because they're relevant then. – Jon Skeet Feb 20 '14 at 16:09
13

Given that there has to be a default, then the most common preference would be the obvious one, and that would be 'off' by default.

Although I could easily do without them, personally I like line numbers because I tend to a) Orientate myself in a code file using them, b) Use them when talking to fellow programmers about code as the quickest way to get them to a specific line of code we're discussing and c) To give a whiff of code smell and remind me of how large a particular code file is getting that I am working on.

Gordon Mackie JoanMiro
  • 3,499
  • 3
  • 34
  • 42
  • 9
    +1 - the lack of orientation is what throws me off when they're hidden, i'm used to knowing about where I am in a file by what line i'm on. – nailitdown Nov 12 '09 at 07:54
  • @nailitdown: Why is that important to you? And doesn't the scrollbar show you roughly where you are relative to the size of the file? The status bar shows you the line containing the cursor... I'm still struggling to see why I need to know the line numbers for *every* line. – Jon Skeet Nov 12 '09 at 09:25
  • 2
    Jon - It's not about "everyone needs line numbers".. It's just a habit of mine - I glance at the line numbers to get a reference of where I am, "OK x() is around 140, y() is around 320." then i can flick around to other parts of the system and flick more or less straight back to where i was. I'm very keyboard-focused so I haven't yet fully adopted the VS drop-downs for going straight to a particular method. – nailitdown Nov 13 '09 at 06:58
  • Doesn't VS have keyboard shortcuts for things like jumping to a specific method? Surely, it must have... says someone who has only used Eclipse. – Per Wiklander Dec 08 '09 at 20:28
2

Its a user preference thing , there is no right or wrong way just create a customs settings file that has it turned on so that you don't have to remember to set it every time (Though i am sure this is only ever done once in a while since you rarely re install VS)

RC1140
  • 8,423
  • 14
  • 48
  • 71
2

A far as I am concerned line numbers are just more screen clutter - I don't see any point in them.

What do you want them for? You're not programming in some 1980s version of BASIC are you?

Dipstick
  • 9,854
  • 2
  • 30
  • 30
  • 4
    even if he did, line numbers have nothing to do with numeric line labels – Rook Nov 12 '09 at 08:05
  • Dipstick, it definitely makes a point in pair programming. How do you tell your partner which part of the code you mean? You don't want to reach over onto the screen to point with your finger - instead you just point out the line number. – Mathias Bader Nov 13 '14 at 11:30
  • @mbader - Bear in mind that my post is 5 years old when screens tended to have less resolution than they do now. Still, every editor I've used in the last 3 decades has a field in the status bar that tells you what line number the cursor is on. You don't need to waste screen space printing a number against each line. – Dipstick Nov 15 '14 at 19:40
2

What does it matter, as long as there is an option to show or hide them?

My preference is to turn them off - I think they are usually a waste of valuable screen space. You can see which line you're on in the status bar, and you can goto (ctrl+G) any line. But there are times when they can be useful.

Jason Williams
  • 56,972
  • 11
  • 108
  • 137
1

Visual studio allow many ways of seeing your code. You can use the searches and drop downs for example. Line numbers may not mean anything to you if you have many named small functions for example. So though I like them its not really an issue is it?

Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
1

For those interested in turning on the line numbers To display line numbers in code

On the Tools menu, select Options.

In the categories list on the left side of the Options window, expand the Text Editor node.

Expand the All Languages subnode and select General to set this option globally.

Note: Visual C# Express user must click Show All Settings to reveal the All Languages subfolder.

—or—

Choose the General options in the subfolder for the language in which you are programming.

In the Display section select Line numbers.

shanethehat
  • 15,460
  • 11
  • 57
  • 87
FUNOW
  • 11
  • 1
0

Line numbers can be of use for one and pain on the screen for another. And all they can help for: quick access to the exact line mentioned in exception stack log and easy way to implement changes introduced by code review.

Anyway, even if there are more usages, there are even more developers who do not use them. And that's a concern of VS developers: they give us means, but they don't switch them all on by default.

terR0Q
  • 1,369
  • 8
  • 17
0

Obviously the only "definitive" answer would have to come from someone on the VS dev team. I always enable line numbers but after reading this post I'm starting to come around. In terms of "why off by default," I don't really see clutter as an issue. However, I do see a compelling argument for "forcing" yourself to not use line numbers. As Jon Skeet mentioned, the only time I really need a line number is from a stack trace. Specifically, from an external stack trace, since AFAIK all internal line references will also lead you right to the line if you click on them. For external references, I can see how I might save myself time by forcing myself to use "go to line" as opposed to hunting for it.

TL;DR? Turn off line numbers and you force yourself to use tools to find a specific line instead of hunting.

scone
  • 566
  • 1
  • 4
  • 12