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 :-)
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityThis 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 :-)
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.
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.
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.
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:
A link which counters some of Dijkstra's points (in an article which is sooner or later gonna come out in this discussion).