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...Numbering should start at zero (1982)
161–170 of 309 posts
Re: Numbering should start at zero (1982)
#162Earlier 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.
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)
#163In 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…
Re: Numbering should start at zero (1982)
#164Earlier 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
(But "oll korrect" is apparently attributed to Andrew Jackson, who was a native speaker, yes.)
Re: Numbering should start at zero (1982)
#165e.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)
#166Always 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…
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)
#167Earlier 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 ?
If you haven't yet, read the tau manifesto: https://www.tauday.com/tau-manifesto
Re: Numbering should start at zero (1982)
#168Whenever 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.
Re: Numbering should start at zero (1982)
#169Re: Numbering should start at zero (1982)
#170Earlier 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.
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.