4 ms·
Still not decided. Matlab, and more recently Julia, also adopted Fortran’s stupid convention.
by jacobolus 10y ago
Still not decided. Matlab, and more recently Julia, also adopted Fortran’s stupid convention.
- azag0 10y agoCan 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
- notalaser 10y agoIt's not stupid when writing mathematics-related code. Few things are more annoying than having to mentally translate between the 1-based indexing in every formula, theorem and equation to the 0-based indexing in a program. I agree (based on Dijkstra's arguments, I'm not smart enough to come up with my own) that 0-based indexing is the more logical, general choice, but 1-based indexing is more convenient for about 99% of the code written in Fortran, Matlab or Julia.
- jacobolus 10y agoIt’s usually better to start from zero in mathematical formulas too (in many cases simplifies them, and most of the rest of the time makes no difference). It’s just that mathematics as a field is very slow to change, and the cultural tradition of starting with 1 is thousands of years old.
- chestervonwinch 10y ago> It’s usually better to start from zero in mathematical formulas too ... No, it's not. There is no universally preferred indexing in mathematics. The indexing scheme that is "natural" changes with the particular application. There are of course instances when 0-based indexing makes more sense [1], [2]. But, there are cases when starting at 1 is more natural, as well [3]. Moreover, there are instances where starting with negative indices is more natural, say with the coefficients of the truncated Fourier series, or with the weights of a finite difference operator or of a cross-correlation operator. Fortran supports all these conventions, which allows for a more direct translation of the mathematics to code. [1]: https://en.wikipedia.org/wiki/Geometric_series#Formula https://en.wikipedia.org/wiki/Geometric_series#Formula [2]: https://en.wikipedia.org/wiki/Taylor_series#Definition https://en.wikipedia.org/wiki/Taylor_series#Definition [3]: https://en.wikipedia.org/wiki/Harmonic_series_(mathematics) https://en.wikipedia.org/wiki/Harmonic_series_(mathematics)
- deleted 10y ago[deleted]
- 10y ago
- FabHK 10y ago> Matlab, and more recently Julia, also adopted Fortran’s stupid convention. Julia, as far as I understand, consciously mimicked Matlab there, to facilitate transition.
- throwaway7645 10y agoLua also uses 1-based.