Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I feel weird when I'm editing code in an IDE that does not have line numbers in the text editor.

The questions I have are:

  1. Are line numbers visually excessive, particularly when a find by line function exists in your IDE of choice?
  2. What are the uses of showing line numbers?
share|improve this question

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

32  
2: Feel totally macho over number of lines of code written. –  Adam Crossland Sep 7 '11 at 17:59
3  
@AdamCrossland: funny you should mention that, I typically see it as exactly the opposite and the more lines of code I write, the more time I end up spending looking over it to make sure I didn't do anything twice and that I'm meeting spec. –  Nick Larsen Sep 7 '11 at 18:08
4  
yeah that's all true for me too, but sometimes you just have to strap on your motorcycle helmet and go for the macho. –  Adam Crossland Sep 7 '11 at 18:12
3  
I find it faster to scroll with an eye on the line numbers than use the goto line function of my editor (that might be because I first have to find it each time), especially when I'm already close –  ratchet freak Sep 7 '11 at 18:44
6  
@Adam : Feel totally Macho at how few lines of codes I have written to make it work. –  Newtopian Sep 8 '11 at 6:30

13 Answers 13

up vote 13 down vote accepted

Anything that aids communication is a plus.

  1. It doesn't take up much space so no, it's not excessive if you or any of your colleagues find it useful to discuss the code.

  2. Even if you don't do pair programming, it is useful for "over the shoulder" code reviews if you don't use tools like Code Collaborator (we don't right now).

Also if you have team members in other sites (we do), it's useful for discussing code via IM or on the phone.

How can you tell them tell them to go to line 1842 if you can't see the line?

For me it's an invaluable simple little tool. Even some of our pdf specs have numbered lines, and it's amazing how much easier it is to refer to and discuss compared to the unnumbered ones.

share|improve this answer

Because when I am using a language (or log file) that tells me the line which caused an error I would like to be able to easily get there.

share|improve this answer

I've found that current line highlighting can solve most "where are you looking" problems. But, the point about stack traces is critical.

share|improve this answer

For whatever reason (cross compiling comes to mind) your compiler may not be integrated into your IDE. Therefore you need an absolute reference for where errors are found. (When you compile outside of your IDE)

NWS

share|improve this answer

Line numbers are also good for estimating methods size, if they are more than 1 screen long (5500 and 9500 LOC per method, we didn't took that guy).

share|improve this answer

One big thing: If you're using Visual studio or any ide with collapsible regions, line numbers give you an instant feel for how big an area is without expanding it. In addition, if you have some sort of logging directing you to a problem line, it's nice to not need to use a command when it's the line is right in front of you.

share|improve this answer

I like to have it when I use split screen in jEdit.

share|improve this answer
    
+1 It definitely helps to orient split screen work in the same file! There are few other ways to determine whether you are looking at the reference or the working area of the file. –  Adam Sep 7 '11 at 20:14

Yes, as @maple_host says, it's really convenient to do a "vi file.py +142" when I see an exception originating from code at that line number. Plus the other mentioned advantages with paired programming etc... It is always beneficial to have the line numbers on, on any editor. (I remember the vague compile error reported by MS VC++ 6 in one of the standard header files, line #blah!!.. It was actually a macro redefinition done by myself!!). Find and kill.

regards, Yati Sagade

share|improve this answer

The only time I've used line numbers is when a bug pops up and the stack trace tells me that it has happened at line x.

I've seen many professional developers working without line-numbers. So, I see no usage other than late referencing.

share|improve this answer

Nobody mentioned being able to quickly look at an exception stack trace to find out where an exception occurred.

share|improve this answer
    
Really? OP states "referencing stack trace line numbers". Or are you both referring to different things? –  StuperUser Sep 7 '11 at 18:25
3  
Oops... I missed that! Well... its important so it is worth reiterating! ;) –  maple_shaft Sep 7 '11 at 18:30
4  
Well the question's been edited now, upvote ahoy! –  StuperUser Sep 7 '11 at 18:36
    
And of course, looking at logs (not necessarily from exceptions). All our logs index the file + line they originate from, incredibly handy! –  Matthieu M. Sep 8 '11 at 18:43
  1. No, I like having the data to give me an idea of where is something in a file, especially if I'm looking at a big configuration file where it may not be easy to find that spot again.

  2. I may glance at the line number as a way for me to see how big is a file. If there are a few thousand lines of code in a file then it may be time to consider if that file should be broken up or something. I can also use it to judge how deep am I in a file if I have a ballpark of the file size and which numbers are on my screen. I like the idea of quantifying my location within the scroll bar, e.g. I'm in the top quarter of the file or 3rd quintile.

share|improve this answer
1  
A few thousand? –  Anthony Pegram Sep 7 '11 at 18:30
4  
@Anthony: You should see loc per file in a game ;) –  Demian Brecht Sep 7 '11 at 18:32
2  
@Anthony: sure. I've seen source files with 10k+ LOC, easily. –  tdammers Sep 7 '11 at 20:21
1  
@tdammers, so have I. The issue is not whether these files exists, it's the point of when is the time to start reconsidering. In my view, that's normally well before a few thousand. It's well before a few hundred. In fact, once I start scrolling, I start to feel a bit antsy (doesn't mean I immediately refactor, mind you). –  Anthony Pegram Sep 7 '11 at 20:46
3  
@Anthony Pegram - I feel that a program should be well structured via functions/routines et cetera. The fact that they are all in the same file does not bother me; quite the opposite; I prefer them all in there instead of a plethora of files in one directory. Easier to diff too, IMO. –  Rook Sep 7 '11 at 21:50

Displayed line numbers are essential for paired-programming. There is no faster way to direct your pair's eyes to the code you are thinking about.

By extension, line-numbers are also extremely useful for code-reviews, both formal and informal.

share|improve this answer
    
+1: Hadn't considered paired programming (not surprising though as I'm definitely not a fan). However, the usefulness of line numbers in code reviews is pretty much turfed if you use an application for it (such as CodeCollaborator) –  Demian Brecht Sep 7 '11 at 18:23
    
I wasn't in the habit of line numbering until I'd done a bit of pair programming, now I'm in the habit of line numbering. +1 for getting me to realize this connection. –  TokenMacGuy Sep 7 '11 at 18:29
10  
Rather than saying "Lines 247 to 253," I find it faster to just highlight those lines, or point to them with my finger. I don't feel this answer is enough to justify the extra clutter. –  BlueRaja - Danny Pflughoeft Sep 7 '11 at 19:18
1  
I'm stunned that this answer received 36 upvotes in 24 hours. –  Eric Wilson Sep 8 '11 at 17:48
    
@BlueRaja: not sure of pair programming either (though you could have both hands occupied), but when discussing from one desk to another, it definitely helps! There's something I don't understand in yyy.cpp at line 314, why do we need that ? –  Matthieu M. Sep 8 '11 at 18:39

I've come from a history of using editors with line numbers embedded in them. My thoughts on the matter? They're absolutely unneeded (I now use Vim with line numbers disabled). Think about this: Even when you do get stack traces and such, how many times do you manually look for the line using line numbers as opposed to ctrl+g (in most Windows editors) or :line-num in Vim?

Edit: Of course, this may be different for others, but 99% of the time, I use the latter.

share|improve this answer

protected by maple_shaft Mar 21 '13 at 18:06

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.