4 ms·
It'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 form
by notalaser 10y ago
It'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]
- kevin_thibedeau 10y ago> but 1-based indexing is more convenient for about 99% of the code written in Fortran, Matlab or Julia. You could make the same argument for octal literals over the scary hex numbers with letters mixed in. 1-based indexing was invented by mathematicians using conventional notation without fully appreciating the problems it causes in computing systems. There is no reason to continue the insanity.
- ska 10y agoIt has nothing to do with not fully appreciating the problems it causes computing systems - many of these notations predates the existence of computing systems or even the though of them. Mathematicians use both zero based and one based systems, sometimes due to mere convention but more often where it is natural to the problem domain. Natural notation has a lot of power to help understand your results. I agree sometimes it is a pain to translate to a physical representation in a computer, but it's not like "just always use zero based" is a good enough answer either.