5 ms·
I don't think 1 based indexing is that useful. A lot of mathematics formulae start from 0 too and 1-indexing makes that more awkward. Although I agree that som
by flubflub 5y ago
I don't think 1 based indexing is that useful. A lot of mathematics formulae start from 0 too and 1-indexing makes that more awkward.
Although I agree that some languages like Julia and say MATLAB feel more fluent to express mathematics.
- ogogmad 5y agoA lot of formulae start from 1 too. And in linear algebra, most of them do. It's like driving on the left side of the road instead of the right side of the road. Inconsistency is what makes it painful.
- noobermin 5y agoI am convinced a good fraction of the off by one errors in C like languages comes from 0 indexing. The ith element is found after traversing i+1 elements and that fact leads to mistakes all the time. With 1 indexing the numbers line up.
- hpcjoe 5y agoI agree. There's far less of a cognitive load for developers associated with representing an expression as written, if you don't need to mess with indices, in order to accommodate the language and its vagaries. One should not need to adjust the way one expresses an algorithm, because of opinionated language design decisions. Put another way, languages designed for scientific/engineering computing won't have a hard/fixed opinion about things that shouldn't be worried about.
- Koshkin 5y agoIndeed, polynomials, for instance, start with a power of zero. At the same time, there is a reason why the natural numbers begin with 1, and, in practical terms, there is a certain convenience in the count (size) being the same as the last index.
- ogogmad 5y agoThe natural numbers don't start with 1... The convention is inconsistent, but for many mathematicians, especially including logicians, they start with 0. It is best not to use the term "natural numbers" at all. By the way, your point about polynomials works in favour of the convention that 0 is a natural number.
- Koshkin 5y agoTry thinking of being the zeroth person in a line. Or your child being in the zeroth year of her life.
- xmcqdpt2 5y agoLuckily, Fortran allows easily changing from one to the other. You simply define arrays as A(1:10) or A(0:9) and they will index from 1 or 0. You can even do arbitrary indexing: fixed like A(-3:3) or dynamically like B(n1:n2). This may sounds useless but it's actually an excellent feature when writing eg convolution kernels. I don't know of any other languages beyond Fortran and Julia that have arbitrary array indexing as a core feature (you can fake it in C in two lines I guess).
- flubflub 5y agoWow that's incredible and really changes my opinion on Julia's indexing. It is small but really makes things more elegant. I should definitely try Julia. I've spent a lot of time calculating awkward array index conversion formulae in my head and this could make things a lot more simple especially for weird cases. I was under the impression that Fortran's only redeeming benefit was that it compiled well for numeric computing routines.
- TheRealKing 5y agoAgain, to be clear, Julia does not have arbitrary indexing as in Fortran. It has an external package that can mimic arbitrary indexing of Fortran.
- adgjlsfhk1 5y agoThat's not a meaningful distinction. Julia is a powerful enough language that OffsetArrays don't need to be built in to work perfectly. Good languages don't need everything built in.
- TheRealKing 5y agoThe comment above states: "...Julia that have arbitrary array indexing as a core feature...". Is an external package written in Julia considered a "core" feature of the Julia language? Why does the Julia community always twist the facts? Why cannot they accept the facts as they are? It would not reduce the value of their efforts, I guarantee you—decency and honesty always prevail.