I really do with the 1 indexing had stayed around, since I feel like it's more natural to say the 1st element, instead of the 0th.
I really do with the 1 indexing had stayed around, since I feel like it's more natural to say the 1st element, instead of the 0th.
It's not the 0th element. It is the 1st element and has an offset of 0 from the beginning of the array.
Not saying it's better or worse, but that if you change the words you use to describe it, you may find it easier to use.
To my surprise, I just learned that ranges in Rust don't include the end number which felt incredibly stupid from a conceptual point of view (python too). But is syntactically useful when doing:
for x in 0..len(my_array) {
My preference would be that a range include the end number and the language provide more python-like iterators and list comprehensions. I am aware that there is a library that provides more python-like syntax, but that doesn't change the oddness of ranges in either language. I guess I just need to remember that the interval is open on one end. Which brings to mind the notion of using [0..n] or [0..n) in a language...
It should be indexed with its position then a[1], as we do in all other aspects of life (and in math), and not with it's offset.
You mean like elevators? You may be surprised to learn that elevators in America are 1-indexed (ground floor == floor 1), but in Europe they are 0-indexed (ground floor == floor 0).
In most European countries the ground floor is not considered the same thing as the others. As Wikipedia puts it: "In most of Europe, the "first floor" is the first level above ground level".
We consider and count as floors the "layers" above the ground level. In french for example, the ground level is called "rez-de-chaussée" and the floors above it "XX étage". The ground level is not an "étage" (in American terms, the "ground level" is not considered a floor, and is not counted among the floors).
For this reason, apart from elevator labels nobody calls the ground level "the 0th floor" when speaking/writing.
And even in elevators, O is just used as a convenient way to convey the ground level (since the buttons don't fit much) -- and not everywhere. In many elevators it gets it own designation (e.g. G or GRD or some other national variety).
It's "the ground level" (with different names per country) + "N floors".
A multi-floor building with ground floor + 3 floors can even named "3rd-storey building" in some countries (and the ground level is just taken as granted) -- e.g. une maison à deux étages in the UK --> 3 story building in the US.
I think you just refuted your own previous assertion that 1-indexing is universal in all other aspects of life.
So, no 0-based indexing here.
We call the house a "3-storey house" not because we zero index, but because the cardinality of it's floors (as europeans define a floor) is 3. In "3-storey building" for Europeans, 3 is the "length", not the last index.
It's no more zero-based indexing than naming relations as “sibling”,“first cousin”,“second cousin” is, just because some hypothetical culture that also uses 1-based indexing but counts siblings as first cousins might rationalize our system as starting with “zeroth cousins” where they have “first cousins”.
What they have merely names what Americans name as zero.
But it's not a stand-in for zero, for us, it's a different entity (a different thing).
A floor (etage, piano, orofos, etc) is a "layer of building where people live above the ground level layer".
So there's no zero-based indexing of floors, because the first item in the set of what are considered as floors is called "first" (e.g. primo in italian).
So, the thing one must understand before they say "same difference", is the other cultural difference: that most European countries don't consider the ground level "floor" to be a floor/story.
I.e, we don't consider the upper floors and the "ground floor" to be in the same set. Which is also why we don't count them when we say a "2 story house" (and we mean a house with 3 such layers, ground story + 2 stories).
Is there a zero-based indexing of the whole "heterogenous" set of ground level + floors?
Well, it's common to have the ground level designated with G or national specific names: BG, BV, E, IS, PB, PT, RC, S, P, PK, etc.
It's just that in some elevators 0 is a substitute for this -- which is probably due to the few common brands and parts being international and nobody bothering to change them (e.g. Otis). That's more a red herring than how Europeans think about floors or index them.
So the floors are numbered according to their distance above the ground level (whatever that's called). This matches my suggestion of treating zero-based indexing as a distance from the first element.
>> Is there a zero-based indexing of the whole "heterogenous" set of ground level + floors?
Yes there is! It's how the elevator buttons are labeled with the possible variation of using a label instead of "0".
The European elevator numbering scheme according to your own comments matches more closely with a zero-based indexing scheme than a 1-based. Or more precisely it matches my proposal to consider the numbers used to reference array elements as distances rather than indexes.
It is true that some elevators label the ground level 0, but this is usually when there are also negative levels (cellars).
The German word Stockwerk is even clearer. It describes the wooden planks which separates two levels. So if you live on the first Stockwerk you live one level above ground.
If I say `for x in range(10)` it iterates exactly 10 times, starting at zero (which is convenient for 0-index lists in python). It would be extremely counter-intuitive if it did [0,10] as it would iterate 11 times. I agree though that it would be much less ambiguous if you could just do `for x in [0..10)`, for example.
Current implementation requires the least amount of "off-by-one" corrections for most tasks, IMO.
Right and I expect that. The issue I have is that the values do not include 10. It turns out great in Python and Rust where things are 0-indexed, but that does not change the fact that the range construct itself is strange in not including 10.
I'm sure the notion of using mathematical notation where [1..10], (0..10], [1..11), and (0..11) all mean the same thing would drive the language parsing people nuts. Mostly because some of those involve unmatched [) or (]. But that's why we have a computer right?
https://doc.rust-lang.org/std/ops/struct.RangeToInclusive.ht...
This is why I think the terminology should be "indexed arrays" and "offset arrays" (and variables perhaps even called index/idx/i or offset/ofst/o as appropriate) instead of using the terms "0-indexed" or "1-indexed."
But I have a hard enough time getting out of the habit myself, and some people are going to hate using o as a variable, so....