3 ms·
Very subjective and context specific argument. Some things are more naturally numbered from 1, others from zero. Fence posts versus fence spans. Pointer arith
by eigenspace 7y ago
Very subjective and context specific argument.
Some things are more naturally numbered from 1, others from zero. Fence posts versus fence spans.
Pointer arithmetic is a great example of a situation well adapted to 0 based numbering, and was quite relevant to many programmers when this was written. However, far fewer programmers nowadays interact with raw pointers directly.
Personally, I run into more cases where I’d rather have 1 based numbering than zero, but your mileage may vary. It’s valuable to have a language which can support both.
- asveikau 7y ago> However, far fewer programmers nowadays interact with raw pointers directly. It doesn't have to be literally a memory pointer to run into the same phenomenon. For example, offsets into a file. I can think of an example when I was doing work on a file format, and 0 based indexing certainly helped simplify some logic.
- eigenspace 7y agoCorrect, I was merely pointing out that the main motivator of Dijkstra’s argument is not nearly as relevant as it was when this was written. I have no idea what indexing style is more appropriate to the hypothetical ‘average’ programmer, but I find myself preferring mostly 1 to N the most, followed next by -N to N and finally 0 to N. As I said originally, your mileage may vary, but I think it’s important that we use languages where many different indexing styles can be supported ergonomically, and in a way that avoids silly errors due to using the wrong index style. Type systems and generic functions help a lot with this. I think of it a lot like say, signed versus unsigned integers. Multiple useful ways of looking at the same bitwise data. Type systems generally save us from nasty errors with the various types of integers. They can do it with arrays too.
- daveFNbuck 7y agoDo you have any examples where 1 to N is a more convenient numbering?
- eigenspace 7y agoWhat are the second to fifth elements of the array A? A[2:5] I find that much much more convenient and user friendly than the alternative.