Live data from Hacker News

Numbering should start at zero (1982)

cs.utexas.edu

91–100 of 309 posts

Re: Numbering should start at zero (1982)

#91
post #13
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 humbly submit '1ndex' and 'ind0x', or '1dx' and 'i0x'.

While most people ran screaming from programming assembly aero142 thought it was a rather swell idea.

Re: Numbering should start at zero (1982)

#92

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…

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.

[deleted]

Re: Numbering should start at zero (1982)

#93
post #87
post #80

Earlier quoted context omitted.

No, it doesn't, it prints ['D', 'C']. I agree that it should be ['C', 'B'] - the way that Python handles negative `step` values is wrong.

I don't think it's "wrong" per se - it's zero-based indexing and ranges are consistently inclusive of start, exclusive of end. But, it breaks the "fence-post" mental model that some people use, and is less intuitive than MatLab's indexing approach IMO.

> I don't think it's "wrong" per se

I do. I think it only makes sense for ranges to be inclusive at the lower end and exclusive at the higher end. A slice with a negative step `-n` should contain the same elements as the same slice as with step `n`, just reversed.

Re: Numbering should start at zero (1982)

#94
post #55

1-based numbering is nonsense. How many years old are you when you’re born? I notice almost all defenses of 1-based indexing are purely based on arbitrary cultural factors or historical conventions, e.g. “that’s how it’s done in math”, rather than logical arguments.

> How many years old are you when you’re born? You have lived zero full years and are in the first year of your life. In most (but not all) countries the former is considered "your age". That's consistent with both zero-based and one-based indexing. Both agree on cardinal numbers (an array [1, 2] has length 2), just not on ordinal numbers (whether the 1 in that array is the "first" or "zeroth" element). > I notice al…

Both agree on cardinal numbers (an array [1, 2] has length 2), just not on ordinal numbers (whether the 1 in that array is the "first" or "zeroth" element).

I think whenever people say "zeroth" they speak in jest and doubt that there is any disagreement on the fact that the element without predecessor (nowadays in programming most often assigned index 0) is the first element.

You used "first" in that sense naturally just in the sentence before without the slightest notion of ambiguity.

You have lived zero full years and are in the first year of your life.

What people wrongly get riled up with is the fact that ordinal (first) is not in sync with the cardinal (index 0), but it rarely is anyways. If you go to an administrative office and pull your number 5357 no one assumes that there are 5356 people in the queue before them. Your are still the 5th or 10th in line, even if your index is 5357.

Re: Numbering should start at zero (1982)

#95
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 Boole Library in Ireland (which has entrances on different floors) they use an algebraic (affine) system. There is a floor designated "Q" and then other floors are labelled relatively, "Q+2", "Q-1", etc.

Re: Numbering should start at zero (1982)

#96
I see people bringing up arrays, and an array index is represented by a number, you can do math on it, but it's not a regular number for counting a sequence of items. It's a unique reference to a location in the memory, and it's dangerous to treat an array index like it's just any old number.

Behold, the really stupid things you can do in Javascript:

  let myArr = [];
  let index = 0;
  myArr[--index] = 5;

  console.log(myArr.length); // 0
  console.log(myArr[index]); // 5

Re: Numbering should start at zero (1982)

#97
post #69

Earlier quoted context omitted.

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…

It's only weird in certain cultures. For example, it's common in Germany to start counting at zero. "Null, eins, zwei.."

Das erste Element in dieser Aufzählung ist jedoch null, und das zweite ist eins. Deutsche verwenden einsbasierte Indizes, genau wie die Amerikaner, auch wenn sie manchmal bei null zu zählen beginnen.

(The first element in this list, however, is zero, and the second is one. Germans use one-based indices, just like Americans, even though they sometimes start counting from zero.)

Re: Numbering should start at zero (1982)

#98

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…

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.

u must be fun at parties

Re: Numbering should start at zero (1982)

#99

Earlier quoted context omitted.

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…

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.

Re: Numbering should start at zero (1982)

#100
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 don't think "index" by itself should imply any starting value. After all many induces start at higher numbers and then you'd have to invent words for 2-based, 3-based and so on as well.
Post reply on HN