TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

2 点作者 redxblood将近 11 年前
I´ve wondered this for many years subconciously. Opinions?

5 条评论

TheLoneWolfling将近 11 年前
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.
bdfh42将近 11 年前
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.
pixeloution将近 11 年前
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>
seren将近 11 年前
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.
ddorian43将近 11 年前
There are have been many discussions on the web about this issue (complaining etc). Just a little search.
评论 #7872397 未加载