Live data from Hacker News

Numbering should start at zero (1982)

cs.utexas.edu

171–180 of 309 posts

Re: Numbering should start at zero (1982)

#171
post #11

I found it devastating that there are no distinct agreed-upon words denoting zero- and one-based addressing. Initially I thought that the word "index" clearly denotes zero-base, and for one-base there is "order", "position", "rank" or some other word, but after rather painful and humiliating research I stood corrected. ("Index" is really used in both meanings, and without prior knowledge of the context, there is real…

I always thought: - Offset: 0-based - Index: 1-based

That sounds reasonable at first, but humans are messy and so the distinction is not always clear.

For example, in music we use numbers for the notes of a scale (G is the 5th of C, because in the C major scale: C=1, D=2, E=3, F=4, G=5, A=6, B=7). The numbers are clearly indices for the notes of the scale.

But we often think of stuff like: what's the 3rd of the 5th -- that is, get the note at the 5th position (G in our example) and then get the 3rd of that note (the 3rd of G is B). But note that B is the 7th of C major, not the 8th you'd get from adding 5 and 3.

The problem, of course, is that we ended up using the numbers as offsets, even though they started as indices.

Re: Numbering should start at zero (1982)

#173

Numbering should start at π (2025) (umars.edu) Seriously, it all depends on whether u're counting the items themselves (1-based) or the spaces btwn them (0-based). The former uses natural numbers, while the latter uses non-negative integers For instance, when dealing with memory words, do u address the word itself or its starting location (the first byte)? The same consideration applies to coordinate systems: r u pos…

Zero is a natural number. It is in the axioms of Peano arithmetic, and any other definition is just teachers choosing a taxonomy that best fits their lesson.

+1 for peano arithmetic club.

I never realized it was controversial. I think I've always included 0 in the nat numbers since learning to count.

But there are some programming books I've read, I want to say the Little Typer, or similar, that say "natural number" or "zero". Which makes actually confuses me.

Re: Numbering should start at zero (1982)

#174

I've always appreciated Ada's approach to arrays. You can create array types and specify both the type of the values and of the index. If zero based makes sense for your use, use that, if something else makes sense use that. e.g. type Index is range 1 .. 5; type My_Int_Array is array (Index) of My_Int; It made life pretty nice when working in SPARK if you defined suitable range types for indexes. The proof steps were…

I think lower..higher index ranges for arrays were used in Algol-68, PL/1, and Pascal long before Ada

At least in standard Pascal arrays with different index ranges were of different incompatible types, so it was hard to write reusable code, like sort or binary search. The solution was either parameterized types or proprietary language extensions

Re: Numbering should start at zero (1982)

#175

I've always appreciated Ada's approach to arrays. You can create array types and specify both the type of the values and of the index. If zero based makes sense for your use, use that, if something else makes sense use that. e.g. type Index is range 1 .. 5; type My_Int_Array is array (Index) of My_Int; It made life pretty nice when working in SPARK if you defined suitable range types for indexes. The proof steps were…

I think lower..higher index ranges for arrays were used in Algol-68, PL/1, and Pascal long before Ada At least in standard Pascal arrays with different index ranges were of different incompatible types, so it was hard to write reusable code, like sort or binary search. The solution was either parameterized types or proprietary language extensions

[deleted]

Re: Numbering should start at zero (1982)

#176

Earlier quoted context omitted.

> I suppose 1-based index is more logical Why?

It's interesting how most people find learning 0-based indexes confusing, but after a few years of programming, they don't even notice how odd it is. How do you number things in real life? If you have two options, do you number them "option 0" and "option 1" or "option 1" and "option 2"? If you create a presentation with numbered bullet points, do you start numbering them from 0 or 1? 1. This is my first point 2. Thi…

Your arguments using "first" and "second" are invalid, because those words have nothing to do with numbers, like also "last".

If you argue based on English, you should point only to the ordinals "third", "fourth" and the like.

In the older European languages, the initial position in a sequence was named using words like "first", which mean "closest to the front". The next position was named with words meaning "the other", e.g. "alter" in Latin (the old European languages had 2 distinct words for "the other from two" and "another one from many", e.g. "alter/alius" in Latin).

However when the need for naming other positions in a sequence besides the first, the second, the last or the next to the last (penultimate) has appeared, then the ordinals derived from numbers have been invented, like third, fourth etc.

In later Latin, the word meaning "the other" has been replaced with a word meaning "the following". This has been inherited in the Romance languages and it has been borrowed in English as "second". Also in Old English, "other" had been used for "second", before "second" was taken from French.

Re: Numbering should start at zero (1982)

#177

I've always appreciated Ada's approach to arrays. You can create array types and specify both the type of the values and of the index. If zero based makes sense for your use, use that, if something else makes sense use that. e.g. type Index is range 1 .. 5; type My_Int_Array is array (Index) of My_Int; It made life pretty nice when working in SPARK if you defined suitable range types for indexes. The proof steps were…

Pascal has it too.

Re: Numbering should start at zero (1982)

#179
post #71

Earlier quoted context omitted.

American elevators are 1-indexed!

at the whitney art gallery (nyc), the ground floor is 1, but the basement is -1. there's no 0 in between it bothers me way more than it should. i have to tell myself that the point of art is often to evoke emotions, and the rage i feel is included in that

In the '80s the ground floor of the EE building (Steele) at Caltech was labeled ⏚. Anyone here happen to know if it is still labeled that way?
Post reply on HN