5 ms·
I understand the mindset that creates this, but I have a different one, I think? Consider the physical world. Let's say you've got three fenceposts (of unit wi
by derefr 10y ago
I understand the mindset that creates this, but I have a different one, I think?
Consider the physical world. Let's say you've got three fenceposts (of unit width) in a line standing before you, each separated by 0.5 fencepost-widths of space.
It makes sense to say "the first fencepost." That's the post can be found in the (0.0, 1.0) region of the fence.
But "fencepost 0" or "fencepost 1" are both ambiguous to me: neither 0 nor 1 is inside the region the first fencepost occupies, physically. The mapping isn't intuitive. Both of those numbers point to where the fencepost isn't: just past its ends. Depending on your mindset, you might want to refer to the fencepost either to the left or the right in the row of that imaginary separating line: either "the fencepost that was just completed" or "the fencepost that is about to start" in your visual stream. Even worse if you're from a culture that reads right-to-left.
In physical terms, if you wanted to give "the first fencepost" an address... it'd be fencepost 0.5! Likewise, "the second fencepost" would be fencepost 2.0, and "the third fencepost" would be fencepost 3.5. These numbers refer to the centers of each fencepost. You don't have to ask the question of which "direction you head" to find the fencepost from the address: when you're at the address, you "have" a fencepost. You just need to know the origin and axes of the fence and you can "go to" the fencepost.
Now, we could get fencepost addresses of 0.0, 1.0, 2.0, and so on, by following some indexing strategy like "the position of the left edge of the Nth fencepost, measuring only fencepost-widths and not space between fenceposts." This kind of offset-based indexing is "intuitive" when talking about memory addresses, because memory addresses are like an ideal fence: every post is 1.0 units wide, with no space in-between posts. (Also, you can't actually point to the centre of an atomic unit of memory; memory addresses are quantized such that the only place the "handle" of a memory address can be attached to the memory itself is the "left edge"—the beginning—of the memory.) Great for digital logic, but we just don't have anything like that in physical space.
In reality, when we want indexes, we explicitly label things with numbers from a monotonic sequence, and then either write down mappings from the center-of-measured-interval addresses of the physical world (e.g. GPS coordinates) to those labels, or, worse, binary-search our items for one with the right address-label, hoping the labels have stayed monotonically sorted since they were issued.
There are nearly no cases where there is a natural "element zero" that exists at zero in the physical world, to create that associative intuition (perhaps, people crossing a finish line in a race: the winner is certainly "person zero" in the photo.)
- zAy0LfpBZLC8mAC 10y ago> But "fencepost 0" or "fencepost 1" are both ambiguous to me Which is good, because it means that you are not confused :-) The confusion is the idea that there is an inherent link between "1" and "first" or "0" and "first", which there isn't, because one of them is a label, while the other is an ordinal number. You need a definition of how to map one to the other, and as long as you don't have that, the labels do indeed remain ambiguous, which you correctly recognize. Now, there is an argument to be made for why array indexing should use a definition that maps the first element to label 0, and that is, as I wrote, that array indexing is an additive operation. As for how that connects to your fence example: What you necessarily need in addition if you want to model your fence with an array(!) is a definition that maps your fence posts' positions to ordinal numbers, which you then can map to array indices via the definition above. That exact mapping is necessarily arbitrary to a degree, and the only really important thing is that you are consistent. But within the implementation, you are likely to encounter problems such as "find the third fencepost of the part of the fence that starts at the second fencepost". And that would be the fourth fencepost of the overall fence, not the fifth, or in indices: 1 + 2 = 3 vs. 2 + 3 != 4. > There are nearly no cases where there is a natural "element zero" that exists at zero in the physical world Well, nor is there a natural "element one" that exists "at one".
- derefr 10y ago> Well, nor is there a natural "element one" that exists "at one". Right. I'm on the "no natural mapping" side as well, here, not with the "first = 1" people. Actually, consider for a moment, a programming language that tried to avoid both of these mappings, at least in its programmer-facing syntax (it might compile down to one or the other mapping, but that's an implementation detail.) It might not be so bad! Of course, you wouldn't be able to index arrays by a single ordinal number at all, instead being forced to do speak in terms of intervals: letters = char{'A', 'B', 'C'} letters[0ch .. 1ch] # => ['A'] letters[1ch .. 2ch] # => ['B'] pairs = short{'AB', 'CD', 'EF'} pairs.slice(0sh .. 1sh) # => ['AB'] pairs[0sh .. 1sh] # => 'AB' pairs[0ch .. 1ch] # => ['A'] or a type error, as the language author pleases pairs[0sh .. 2sh] # => argument error pairs.slice(0sh .. 2sh) # => ['AB', 'CD'] Effectively, the single-element index operation would just be a specialization of a slice operation. Both operations would take a mantissa indicating where the "left edge" and "right edge" containing the value you want is in the array's memory space. And you'd be forced to specify explicit units for the "addresses" of the mantissa, even though the language might reject a mantissa of the wrong type. This seems kind of annoying to write. But, I swear, it feels so pleasant to read. Much moreso than any language I've used. It's not hard at all to "keep the logic in my head" when I read the above back.