TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Would programming be easier if we started indexes at 1?

2 pointsby redxbloodalmost 11 years ago
I´ve wondered this for many years subconciously. Opinions?

5 comments

TheLoneWolflingalmost 11 years ago
It depends on what you&#x27;re using the indexing for.<p>Having played around with Lua (In a mod for Minecraft, of all things), I&#x27;ll say that 1-based indexing is better for some things, while zero-based indexing is good for other things.<p>One of the nice things about 1-based indexing is that for basic &quot;display a list to the user with indexes&quot; purposes, you don&#x27;t need to add one all over the place. But at the same time with 0-based indexing you don&#x27;t need to check the lower bound in a lot of cases.
bdfh42almost 11 years ago
Short 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.<p>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.
pixeloutionalmost 11 years ago
The canonical argument for starting indexes at 0: <a href="http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html" rel="nofollow">http:&#x2F;&#x2F;www.cs.utexas.edu&#x2F;users&#x2F;EWD&#x2F;transcriptions&#x2F;EWD08xx&#x2F;EW...</a>
serenalmost 11 years ago
Then 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&#x27;t think it would make any difference.
ddorian43almost 11 years ago
There are have been many discussions on the web about this issue (complaining etc). Just a little search.
评论 #7872397 未加载