3 ms·
Ask HN: Would programming be easier if we started indexes at 1?
I´ve wondered this for many years subconciously. Opinions?
- ddorian43 12y agoThere are have been many discussions on the web about this issue (complaining etc). Just a little search.
- redxblood 12y agoI don´t doubt that, but i´m searching more of a personal opinion rather than objective aproaches.
- seren 12y agoThen in C, *(p+10) would reference array[11], which would probably cause its own kind of error and misunderstanding. The only winning move is not to play? I don't think it would make any difference.
- pixeloution 12y agoThe canonical argument for starting indexes at 0: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...
- bdfh42 12y agoShort answer no - programming would be just a little bit more difficult. Calculating an index can often be simplified if zero is not just a valid value but the first element in an array or character in a string or what have you. I base this on the active experience of having worked (over the years) with 1 based index languages and (even) languages (VB Classic) where you could set the lower as well as upper bounds of an array. Zero based arrays (and such) are generally just that bit easier to work with.
- TheLoneWolfling 12y agoIt depends on what you're using the indexing for. Having played around with Lua (In a mod for Minecraft, of all things), I'll say that 1-based indexing is better for some things, while zero-based indexing is good for other things. One of the nice things about 1-based indexing is that for basic "display a list to the user with indexes" purposes, you don't need to add one all over the place. But at the same time with 0-based indexing you don't need to check the lower bound in a lot of cases.