Live data from Hacker News

Numbering should start at zero (1982)

cs.utexas.edu

241–250 of 309 posts

Re: Numbering should start at zero (1982)

#241
post #121
post #25

Earlier quoted context omitted.

AFAIK "offset" (i.e. from the beginning of the array/file/etc) is commonly used to indicate a zero-based index.

I like this. I feel like "offset" hints at the reason for starting at 0. "How far do you have to offset your feet (from the beginning of whatever space we're talking about) before you're touching the thing in question?" If it's the first thing, you don't have to move at all, so zero offset

Of course you could also "offset your feet" until they're past the end of the last thing, and then you've counted the number of things. But the offset of the thing itself (as opposed to that of your feet) could be considered zero, assuming the natural position of the thing is for its left edge to be at the left edge of the space.

But maybe its natural position is to be centered at x=0 and it had to be moved by 0.5 for the left edges to line up, in which case see my other comment.

In any case, I think the argument over 0 or 1 or 0.5-based indexing can be resolved just by being clear about what it is you're counting.

Re: Numbering should start at zero (1982)

#242

Earlier quoted context omitted.

I want to be rude. The mix of "The same consideration applies to coordinate systems:" and "r u positioning urself..." in the same message is ridiculous to me and I can't take anyone seriously who speaks like this. It's not illegal or immoral, but it is at the very least, demonstrably distracting from their own actual substantive point. Here we all are talking about that when they otherwise had a perfectly good observ…

People taking such offense to something so absolutely inconsequential, on an internet forum no less, is ridiculous to me and I can't take anyone seriously who gets worked up about it. You, and parent poster, understood them fine. You, and the parent poster, are the ones who are steering the conversation in the direction of how they typed, not what they typed. They had a "perfectly good observation to talk about", yet…

It's at least as valid, in fact more so, to say that I was distracted by something they decided to say.

There is no objective way to assign all blame for the tangent to just us or just them, however the closest you can come is to say that whoever speaks first is more responsible for their unprompted speech than responders are for their reactions. They chose their reactions, but they are not reactions in a vacuum, they are reactions to something, that came from someone else.

Re: Numbering should start at zero (1982)

#243
post #103

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…

I totally disagree, but it's only my opinion and probably not scientific at all. From a logical point of view I think it's totally unnatural to start at 1. You have 10 diffferent "chars" available in the decimal system. Starting at 1 mostly leads to counting up to 10. But 10 is already the next "iteration". How do you explain a kid, who's learning arithmetics, that the decimal system is based on 10 numbers and at the…

The reminds me of the pain I felt seeing how the blacktop was painted at the local elementary school:

They had a 6 x 6 grid with 26 letters, then the digits 1-9, then an extra X to fill in the space left over. :facepalm:

Re: Numbering should start at zero (1982)

#244
post #27

Earlier quoted context omitted.

It makes more sense if you think of indices as pointing between elements: 0 1 2 3 4 ----------------- | A | B | C | D | ----------------- -4 -3 -2 -1 -0 Except, of course, -0 doesn't exist. AFAIK that's why C# chose to add a special "index from end" operator, `^`, instead of using negative indices.

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.

Values take up space. When you manipulate a value or pass it around, it makes no sense to sometimes refer to the beginning of the value and sometimes to the end.

It makes a little more sense if you have an array of something other than plain integers. Let's say you have 2-tuples:

     0        1        2        3        4        5
     | (0, 1) | (1, 1) | (1, 2) | (2, 3) | (3, 5) |
    -5       -4       -3       -2       -1       -0
or perhaps a better display would be more memory-based, where a tuple is represented as a pair of bytes:

     0   1   2   3   4   5
     00010101010202030305
    -5  -4  -3  -2  -1  -0
Now -3 clearly refers to the beginning of an array element. At least I wouldn't expect -3 to refer to (1, 1), even though I'm mentally traversing right to left for negative indexes.

Or another way to think about it: arr[5] does not exist in the above example. It's the end of the array, and the end is exclusive. Negative indexes count from the end. -0, as a result, refers to the (unmodified) end, which is the nonexistent thing, same as arr[5].

And yet another way: think of positive indexes as going forward, negative as going back. Imagine a syntax arr[3][-2] where arr[3] gives you the subarray starting at offset 3. (In C or C++, this would be like (&arr[3])[-2] with an array type that supported negative indexes, which implies it tracks subarray length.) Where should you end up? Start with the simpler case of arr[3][-0] -- clearly that should be the same as arr[3], not arr[2], if you are "going back 0". And if you're starting out with 0-based indexes, then the "going forward"/"going back" interpretation is inescapable.

As a bonus, arr[-n] is the same as arr[arr.length() - n]. But that's just a lucky happenstance; I wouldn't argue that the semantics of negative indexes should depend on it. Well... one could argue that arr[arr.length()] is the (nonexistent, exclusive) end.

Re: Numbering should start at zero (1982)

#245

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…

Actually, the duality arises from counting (there can be 0 items) and ordering (there is only a 1st item), conceptually. Which is why the year 2000 can and cannot be the start of the 3rd millenium, for instance.

Fun fact: the words Ordinal and Cardinal respectively derives from Ordering and Counting.

So Ordinal quantities represent the ordering of coordinates and can be negative, while Cardinal quantities describes the counting of magnitudes and must be positive.

You can transform between ordinal domains and cardinal domains via the logarithm/exponential function, where cardinal domains have a well-defined “absolute zero” while ordinal domains are translation-invariant.

Re: Numbering should start at zero (1982)

#246

>> when starting with subscript 1, the subscript range 1 ≤ i What about the range 0 < i ≤ N which starts with 1? Why only use ≤ on the lower end of the range? This zero-based vs one-based tends to come up in programming and mathematics, and both are used in both areas. Isn't it obvious that there is no universally correct way to index things?

I believe the main argument (from the OP) is that you have to specify the range with two bounds, and that it is common to want a 0 (assuming a 0-based indexing world), and so in order to refer to a range that includes index 0 you'll need to use a number that is not in the set of valid indexes to define the bound.

I would note that the argument is weakened when you look at the later bound, since you have the same problem there, it's just more subtle and less commonly encountered -- yet it routinely creates security bugs!

It's because we don't work with integers, we work with fixed-size intervals within the set of integers (usually a power of two consecutive integers). So `for (i = 0; i = LIMIT) { return error; }` doesn't work if your LIMIT is based on the representable range. Nor does `if (n * elementSize >= LIMIT) { return error; }`. Even doing `limit = LIMIT / elementSize; if (n >= limit) { return error; }` requires doing the `LIMIT / elementSize` intermediate calculation in larger-width numbers. (In addition to the off-by-one if LIMIT is not evenly divisible by elementSize.)

So when dealing with overflow checks, 0 ≤ i ≤ N may be better. Well, a little better. `for (i = 0; i > Isn't it obvious that there is no universally correct way to index things?

I don't know about "obvious", but I agree that there is no universally correct way to index things.

Re: Numbering should start at zero (1982)

#247
post #178

Where I live and maybe where you live our ages are zero based although no one seems to like me calling their baby zero years old.

Well, "three months old" does sort of imply "zero years and three months".

But thank you for reminding me that I am zero centuries old. More decades old than I would like, but zero centuries.

Re: Numbering should start at zero (1982)

#248

Earlier quoted context omitted.

People taking such offense to something so absolutely inconsequential, on an internet forum no less, is ridiculous to me and I can't take anyone seriously who gets worked up about it. You, and parent poster, understood them fine. You, and the parent poster, are the ones who are steering the conversation in the direction of how they typed, not what they typed. They had a "perfectly good observation to talk about", yet…

It's at least as valid, in fact more so, to say that I was distracted by something they decided to say. There is no objective way to assign all blame for the tangent to just us or just them, however the closest you can come is to say that whoever speaks first is more responsible for their unprompted speech than responders are for their reactions. They chose their reactions, but they are not reactions in a vacuum, the…

Both reactors and reactees have equal opportunity not to speak.

A reactor who reacts simply to nitpick provides much less to a conversation than a reactee with interesting thoughts expressed unusually.

Re: Numbering should start at zero (1982)

#249

Explains why he didn't like APL...

He also hated Lisp

I don't know of evidence that he did. But Dijkstra left us a famous quote:

"LISP has jokingly been described as “the most intelligent way to misuse a computer”. I think that description a great compliment because it transmits the full flavour of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts."

This is obviously a compliment; it even mentions that word.

Even a less positive remark than this would still be resounding compliment from a computer scientist who said things such as that BASIC causes irreparable brain damage!

So count this as a piece of evidence that he liked Lisp.

Lisp emphasizes structured approaches, and from the start it has encouraged (though not required) techniques which avoid destructive manipulation. There is a lot in Lisp to appeal to someone with a mindset similar to Dijkstra.

Re: Numbering should start at zero (1982)

#250

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…

Actually, the duality arises from counting (there can be 0 items) and ordering (there is only a 1st item), conceptually. Which is why the year 2000 can and cannot be the start of the 3rd millenium, for instance.

I don't follow the distinction you're making. The number line is ordered and contains a 0....

The GP's explanation seems more fitting for the year 2000 ambiguity. Are you measuring completed years (celebrate millenium on NYE 2001) or are years the things happening between 0 and 1, 1 and 2, etc (celebrate on 2000, because we're already in the 2000th "gap")?

Post reply on HN