Live data from Hacker News

Numbering should start at zero (1982)

cs.utexas.edu

161–170 of 309 posts

Re: Numbering should start at zero (1982)

#161
This article is one my pet peeves. It always shows up in discussions as "proof" that 0 indexing is superior, but it hides under the carpet all the cases the where it is not. For instance, backwards iteration needs a "-1" and breaks with unsigned ints.

    for (i=N-1; i>=0; i--)
I like the argument that 0-based is better for offsets and 1-based is better for indexes: https://hisham.hm/2021/01/18/again-on-0-based-vs-1-based-ind...

Re: Numbering should start at zero (1982)

#162
post #16

Earlier quoted context omitted.

But on the other hand, last := vector[vector-length(vector)]; is nicer than last := vector[vector-length(vector) - 1]; so in the end I'd say 'de gustibus non est disputandum' and people who prefer 0-based indexing can use most languages and I can dream of my own.

That's arguably one of the only downsides of zero-based, and can be handled easily with negative indexing. Basically all indexing arithmetic is easier with zero-based.

Using an array as a heap is also easier with 1-based indexing:

  base-element := some-vector[i];
  left-child := some-vector[i * 2];
  right-child := some-vector[i * 2 + 1];
where the root element is `some-vector[1]'.

Re: Numbering should start at zero (1982)

#163

In France, street-level is the 0th floor, and the one above is the first floor. You see zero in elevators all the time.

Same in Germany, just that we usually call it ground floor instead of 0th floor. You could argue it's a bit of a translation error. The French and German words for floor are referring to ways to add platforms above ground. Either by referring to walls, wooden columns or floor joists. Over the course of language evolution those words have both broadened and specialized, referring to building levels in general. But the…

It’s the same in non-American Anglo countries as well. Zero-indexed with the zeroth floor being called “ground”.

Re: Numbering should start at zero (1982)

#164
post #138

Earlier quoted context omitted.

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.

Wasn’t the guy who wrote “all correct” as “oll korrekt”[1] a native [American] English speaker also? —- 1. https://en.m.wikipedia.org/wiki/OK

Not to contradict you, but fascinating coincidence: my favorite alleged originator of OK — "Old Kinderhook," Martin Van Buren — is to date the one and only U.S. president who did not speak English as his first language.

(But "oll korrect" is apparently attributed to Andrew Jackson, who was a native speaker, yes.)

Re: Numbering should start at zero (1982)

#165
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 generally much easier and frequently automatically handled.

Re: Numbering should start at zero (1982)

#166
post #160

Always beware the word should. I agree with Dijkstra's logic in the context that he presents it, but there are other contexts where I don't think it applies. Personally, I find that in compiler writing, which is the only programming I do these days, the only things I use indexes for are line numbers and character offsets into strings. Calling the first character the zeroth character is ridiculous to me, so I just sto…

Not only is this preference not restricted to compiler programming, but it's not even restricted to programming.

Try to count 4 seconds, if you start at 1 you messed up. Babies start at 0 years old. Etc..

I do agree it's a convention though. Months and years start at 1, but especially for years, only intervals are meaningful, so it doesn't really matter what zero is (even though christ is totally king)

Re: Numbering should start at zero (1982)

#167
post #148
post #144

Earlier quoted context omitted.

I think we can pretend now that anyone talking about pi is just being sarcastic? It is such a random and useless number, a perfect candidate for a funny meme

> It is such a random and useless number Random ? Useless ?

Yes to both!

If you haven't yet, read the tau manifesto: https://www.tauday.com/tau-manifesto

Re: Numbering should start at zero (1982)

#168
post #117

Whenever I explain to someone when or why to use 0-indexing, I like to say: Start from 0 if you are counting boundaries (fenceposts, memory addresses) Start from 1 if you are counting spaces (pages in a book, ordinals) Floors are a case where both make intuitive sense, which is maybe how we ended up with European vs American floor numbering.

That's a very confused way of thinking about it IMO. I say: * Start from 0 if you are indexing . I.e. you are identifying an item or its position. * Start from 1 if you are counting . I.e. you are saying how many items there are. It doesn't matter what it is. I don't know why you think pages in a book are somehow different to memory addresses.

You know what I like this much better...rule of thumb updated.

Re: Numbering should start at zero (1982)

#170
post #58

Earlier quoted context omitted.

> 1-based numbering is nonsense. How many years old are you when you’re born? Typically 3 months shy of 1 year, so about 0.75.

The key word in "birthday" is "birth". Not conception. For human cultural purposes, you are 0 days old at the time and date recorded for your birth. It goes on your birth certificate. If you find a culture that celebrates conceptiondays and issues conception certificates, let me know.

The comment I’m replying said nothing about “birthday”. They asked how many years old you are when you’re born, which is ambiguous.

You know some cultures don’t even celebrate birthdays, right? It’s not even uncommon for people to not know their date of birth. Even my own grandmother, born in Chicago in the 1920s, didn’t even know exactly what year she was born in.

Post reply on HN