5 ms·
> It really shows how conditioned an entire community can be when they find the statement “given a list x, the first item in x is x[1], the second item in x is
by steerablesafe 6y ago
> It really shows how conditioned an entire community can be when they find the statement “given a list x, the first item in x is x[1], the second item in x is x[2]” to be unnatural.
It's not unnatural, but it's not natural either. It's just that 1-based indexing aligns with natural language conventions better. It also matches with some math conventions for matrices and vectors, but those don't have to use 1-based indexing either to work. I learned linear algebra with abstract "index sets" (I), where I can be {1, 2, 3, .., n}, {x,y,z}, {0,1,2}, whatever.
Programming in 0-based indexing means way less +-1 adjustments on boundaries. Division/modulus also works way better with 0-based indexing, so flattening multi-dimensional arrays is more easily expressed too.
In the end it's just a convention, it shouldn't matter too much. My money is still on 0-based indexing, as it lends itself to less errors and cognitive load when you get used to it. I used both extensively.
Tangential: conventions that are more "natural" are usually not actually natural, but just align themselves to other conventions better. Of course it's always good if conventions align, but sometimes it's inconsequential. Also there are situations where we can't make all conventions align.
An other little pet-peeve of mine is people calling big-endian more natural than little-endian, where there are actually different competing conventions:
1. Usual way of printing memory content from lower address to higher address from left to right (think hexdump).
2. Usual way of writing down numbers from left to right from most significant digit to least significant digit.
3. Expressing the value of the number from the byte array elements (\sum_0^(width-1) byte[n] 256^n for little-endian, \sum_0^(width-1) byte[n] 256^(width-n-1) for big-endian)
Big-endian aligns better with the combination of 1 and 2. Little-endian aligns better with 3.
- threatofrain 6y ago> It's just that 1-based indexing aligns with natural language conventions better. What about how Europeans index their building floors from 0?
- robertlagrant 6y agoOr what number does a stopwatch start from?
- steerablesafe 6y agoI think a stopwatch is a different beast from 0-based or 1-based indexing. A stopwatch is used to measure the time interval between two events. If stopwatches could somehow magically measure and display time in infinite precision we wouldn't have this discussion. But if they do rounding to the nearest displayable number then they display 0 for half of the time-step interval, then display the subsequent numbers for the full time-step interval each. I vaguely remember that the original minesweeper started counting time from 1, which is certainly odd. I could be wrong here though.
- simiones 6y agoWell, that's usually a more complicated discussion. In French and Romanian at least, the word used for "floor" in this context ("etage"/"etaj") refers to an elevated construction. So, a building with "1 floor" ("1 etage") has 1 elevated construction atop the ground. This is what leads to the apparent 0-based numbering. The numbering is actually 1-based, but people count the extra layers above the ground, instead of literally counting the floors. In fact, I have rarely seen elevators show a 0 - they normally have something like P, 1, 2, 3. It's more complicated anyway, since there are many structures with intermediate floors below or slightly below the ground, and those are usually nominated specifically ("mezzanine", "demisol" , etc.).
- yiyus 6y agoElevators with a 0 are very common, at least in some countries. And -1 for the garage.
- d3ckard 6y agoThis is not the best example. In Polish for example there is a whole different word for ‘0’ floor (parter), and the word for the rest of floors (piętro) kind of assumes that level is above ground, so we do use 1 based indexing there.
- varajelle 6y ago> 2. Usual way of writing down numbers from left to right from most significant digit to least significant digit. Fun fact: the numbers are imported from Arabic in which they are originally meant to be read from right to left => little-endian