4 ms·
Can we stop calling it stupid? It's different. I prefer 1-based in Fortran where I deal exclusively with matrices, and 0-based in any more general programming.
by azag0 10y ago
Can we stop calling it stupid? It's different. I prefer 1-based in Fortran where I deal exclusively with matrices, and 0-based in any more general programming.
- nemoniac 10y agoHere's Dijkstra arguing the case well: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...
- effie 10y agoI see no argument there, only a subjective statement "0 ≤ i < N is nicer". To me, 1 ≤ i ≤ N is nicer because it is what most people think when they see sequence 1..N. In addition, the last number of the sequence indicates the count of the members.
- Athas 10y ago> In addition, the last number of the sequence indicates the count of the members. This is only the case for 1..N, not for I..J, when 'I' is not one. In this general case, the number of elements is 'J-I' if using zero-based numbering and exclusive upper bounds, which is more convenient. Zero-base also simplifies index arithmetic with modulo operations, such as when you are mapping between different index spaces.
- nemoniac 10y agoIt's not so much that it's "nicer". It's that it's simpler. In his "Simple Made Easy" talk, Rich Hickey quotes Dijkstra saying "Simplicity is a prerequisite for reliability". Here's some more grist to the mill, currently on the HN front page: https://news.ycombinator.com/item?id=13547317 https://news.ycombinator.com/item?id=13547317