3 ms·
I had a job about 7 years ago doing Coldfusion and Flash. Coldfusion is 1 indexed and Actionscript is 0 indexed...this threw me off enough to the point of havi
by tombert 8y ago
I had a job about 7 years ago doing Coldfusion and Flash. Coldfusion is 1 indexed and Actionscript is 0 indexed...this threw me off enough to the point of having a near-religious aversion towards explicit indexing, and while I've largely drunk the functional Kool-aid where I almost exclusively use maps and filters and reduce.
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.
- phkahler 8y ago>> 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...
- coldtea 8y ago>It's not the 0th element. It is the 1st element and has an offset of 0 from the beginning of the array. 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.
- umvi 8y ago> as we do in all other aspects of life 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).
- coldtea 8y agoAs a European I'm not really surprised, but it's not exactly the same thing. It's not like the ground level is considered "the 0th floor" and thus we use 0-based indexing. 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.
- oblio 8y agoYup, for Europe I'd actually be curious which countries don't consider the first floor the one above the ground floor, since they're probably the minority.
- phkahler 8y ago>> A multi-floor building with ground floor + 3 floors can even named "3rd-storey building" in some countries I think you just refuted your own previous assertion that 1-indexing is universal in all other aspects of life.
- coldtea 8y agoNot sure what you mean. There are 3 floors (as europeans define a floor, ie. anything ABOVE what americans call ground floor) and are named floor 1, floor 2 and floor 3. 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.
- umvi 8y agoPython almost always does what I want. 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.
- phkahler 8y ago>> If I say `for x in range(10)` it iterates exactly 10 times 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?
- nicoburns 8y agoRust actually has both [0..=n] is inclusive https://doc.rust-lang.org/std/ops/struct.RangeToInclusive.html https://doc.rust-lang.org/std/ops/struct.RangeToInclusive.ht...
- wwweston 8y ago> It's not the 0th element. It is the 1st element and has an offset of 0 from the beginning of the array. 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....