Live data from Hacker News

Numbering should start at zero (1982)

cs.utexas.edu

131–140 of 309 posts

Re: Numbering should start at zero (1982)

#132

Earlier quoted context omitted.

So if you go into a bar and order a beer, you drink the zeroth beer before the first?

You would, if English were logical as opposed to being a randomly-evolved cultural practice. With computer languages we have the opportunity to fix the mistakes of the past and do better.

[deleted]

Re: Numbering should start at zero (1982)

#133
post #20

"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration." — Stan Kelly-Bootle

Python supports a third way: start at -1. And if you think about it a little (but not too much) then there's some real appeal to it in C. If you allocate an array of length n and store its length and rewrite the pointer with (*a+=n)=n, then a[0] is the length, a[-1] is the first element (etc) and you free(a-a[0]) when you're done. As a nice side effect, certain tracing garbage collectors will never touch arrays stored in this manner.

Upshot: if you take the above seriously (proposed by Kelly Boothby), the median proposed by Kelly-Bootle returns to the only sensible choice: zero.

Re: Numbering should start at zero (1982)

#134

Earlier quoted context omitted.

You are just citing cultural factors like how we happen to do things in the English language, not any logical argument.

Are there any languages that call the first element the zeroth element in everyday speech? I can't think of one, Google can't come up with one, and neither can ChatGPT. This isn't just cultural; it's universal or almost universal.

Not zeroth but ground floor vs 1st floor in buildings is common.

Re: Numbering should start at zero (1982)

#135

Earlier quoted context omitted.

Why do you write “you” as “u” here? I don’t want to be rude, but it’s very jarring to see juvenile txt-speak in a serious discussion.

I dare u to correct sama’s tweets ;)

Who?

Re: Numbering should start at zero (1982)

#137

Earlier quoted context omitted.

Your visualization makes sense if you always count them going from left to right. But with negative index you naturally count them going from right to left, from the last element backward to the first element. So -0 is the natural starting-point, except it's -1 in python.

-1 is correct, there is no -0. The math works correctly the Python way.

Indexing is not really math, it's a reference-system which is using numbers for convenience. You could use letters or even emojis to get the same result.

Re: Numbering should start at zero (1982)

#138

Earlier quoted context omitted.

Why do you write “you” as “u” here? I don’t want to be rude, but it’s very jarring to see juvenile txt-speak in a serious discussion.

“serious discussion” notwithstanding, I thought the “u’re” was particularly interesting. Why not “ur”? “u” is obviously easier to write, so why worry about properly contracting it? Just interesting imo

It wasn’t clear to me what “u’re” was and I wouldn’t have understood without the comment. I’m a native English speaker.

Re: Numbering should start at zero (1982)

#139
post #134

Earlier quoted context omitted.

Are there any languages that call the first element the zeroth element in everyday speech? I can't think of one, Google can't come up with one, and neither can ChatGPT. This isn't just cultural; it's universal or almost universal.

Not zeroth but ground floor vs 1st floor in buildings is common.

That's a good example! Elevators sometimes have a 0 for the ground floor, but they often have an "E" in German-speaking countries or a "C" in English-speaking countries.

In this example, people also call the floor with index 1 the "first floor," although they don't call the ground floor the zeroth floor, as you say.

Since floors can go below ground, the first underground floor is floor -1, so everything works out. There's a floor for every number, unlike with 1-based floor numbering, where floors go from -1 to 1.

Re: Numbering should start at zero (1982)

#140

Earlier quoted context omitted.

Why do you write “you” as “u” here? I don’t want to be rude, but it’s very jarring to see juvenile txt-speak in a serious discussion.

I dare u to correct sama’s tweets ;)

It’s stupid when he does it too.
Post reply on HN