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.

This just struck me as an oversight by Microsoft. Since arrays and other data-structures within the .NET framework begin from zero (zero-based) why don't we have a line 0 within the code view in Visual Studio?

Ponder that one :-)

share|improve this question
    
Visual Studio is older than .NET. By a lot. (True, it is written in another zer-based language, but my point is no .NET convention should be assumed to drive Visual Studio decisions.) –  Kate Gregory Aug 18 '11 at 14:09
    
    
Because no one answering this question has a sense of humour? ;-) –  HappyCat Aug 18 '11 at 14:53
2  
Every commercial product has a product manager / marketing director, whose job it is to maximize the friendliness and minimize the shock value to buyers, so they buy. Only programmers think zero is the first number. –  Mike Dunlavey Aug 18 '11 at 16:10
1  
@MikeDunlavey, but the point is, Visual Studio is made for programmers! –  svick May 8 '12 at 0:47
show 2 more comments

6 Answers 6

Because they did a good job at separating the user model from the programming model, that's why. The same reason why most apps don't ask you, for example,

Please enter a varchar(200) representing your name.

Take a lesson from that.

share|improve this answer
2  
Great answer. A lot of programmers can benefit from thinking like a user again. –  MattK311 Aug 18 '11 at 21:40
    
I agree with this answer, but I don't think this answer is necessarily as obvious as JohnFx's tone would imply. In the case of Visual Studio (or any IDE), there's no difference between the "user model" and the "programming model", since all users are likely programmers. If I am writing software for some aliens who use a base-37 numerical system, my user model will necessarily display integers in base-37. So, if I'm writing an IDE for programmers, who are most likely used to thinking in zero-based indexing, isn't that also my user model?? –  Charles Salvia Jul 17 at 21:06
    
I strongly disagree. Just because the user is a programmer does not make zero based counting part of the user model. Programmers only use zero based systems because the compiler expects it. Now if you were writing software where a COMPUTER was the user I would agree. I've been a programmer all my life and I do not count real world objects starting with zero. –  JohnFx Jul 18 at 20:34
add comment
  1. All arrays and data-structures are indexed based on zero, not just in .NET.
  2. Array indexes are numbered for the computer, text lines in a document are numbered for us.
  3. See screenshot :)

enter image description here

share|improve this answer
7  
+1 for the screenshot :) –  Spoike Aug 18 '11 at 11:16
9  
"All array and data-structures are indexed based on zero" -- this is not true, all arrays are not zero-indexed, though it's quite common these days. Many historical languages used mathematical-style 1-based indexing (Fortran and COBOL come to mind) but even the more modern Lua uses 1-based indexing. –  Dean Harding Aug 18 '11 at 12:21
1  
@Dean Harding I meant they are - internally. Numbering them from 1 is sort of syntax sugar. At least this is my understanding...? Anyhow, .NET standard is much more of a rule than an exception in this aspect. –  Konrad Morawski Aug 18 '11 at 12:24
    
Worth noting than VS is not the only editor doing this and that it would be harsh to blame it for its behavior. Even Emacs numbers lines starting from 1 (and rightly so, as you pointed out). –  haylem Aug 18 '11 at 13:36
2  
Inception or recursion? –  Kevin Aug 18 '11 at 15:25
show 2 more comments

There is a difference between counting and indexing. The index can start at any number (some languages support that), but for many reasons it is most often practical to have it start at zero. Counting also starts at zero, but as soon as one does count a set that is not empty, the first element is 1, and so on.

share|improve this answer
2  
+1 for the difference between counting and indexing. –  Jeremy Heiler Aug 18 '11 at 14:43
add comment

Because it is not natural to assume that the first line is the 0th line. Much like it's not natural either that arrays first element is at 0. However that's the first number that can be used in an unsigned integer to index an array with. So instead of wasting one element we use it.

share|improve this answer
3  
In the case of counting, you say how many elements you have. While in indexing, you merely tell the difference to the base index. –  Ingo Aug 18 '11 at 13:12
add comment

By convention, normal humans count starting from 1, while many programmers and some mathematicians count starting from 0.

The question you have raised about line numbers is not specific to Microsoft Visual Studio. It applies to every other text editor tool, because counting lines from 1 has been adopted as a universal convention in software.

The countless other tools that count text lines from 1 include Windows Notepad, IDE text editors, text editors on Linux, Firefox's JavaScript console, compiler error messages, and so on and so forth.

While it wouldn't be wrong to count lines starting from 0, it would break the established convention and cause a massive amount of confusion to everyone involved, from the developers to the users.

See also:

share|improve this answer
    
"massive amount of confusion"? Probably not... –  Kenneth Aug 18 '11 at 14:11
    
I don't know any mathematicians (and I do know quite a few) that start counting from one. They deal with 0 when needed in where needed, but in real life they all count from one. –  Rook Aug 18 '11 at 14:26
add comment

A link which counters some of Dijkstra's points (in an article which is sooner or later gonna come out in this discussion).

Why numbering should start at one

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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