4 ms·
> Iterators have largely replaced the explicit specification of integer ranges in loop control. Yes, explicit indices are less common than they used to be due
by avian 10y ago
> Iterators have largely replaced the explicit specification of integer ranges in loop control.
Yes, explicit indices are less common than they used to be due to iterator support in languages. However they are far from being obsolete. I've been recently going through a lot of code dealing with numerical calculations and there you see hardly any iterator use.
Also, MATLAB code, which uses 1-based indices, is an absolute pain to deal with compared to Python/numpy, for example.
- tnecniv 10y agoMaybe I've been drinking to koolaide for too long (and it's not a good flavor), but the 1-based indices in MATLAB are not bad once you get used to them. They're especially nice when translating mathematical papers that normally index from 1.
- goatlover 10y agoYeah, I don't get the love for 0 base, unless you're doing C level stuff, which is the real reason for 0 based indexing.
- avian 10y agoI guess it depends on the field you're working with. I'm definitely more at home with 0-based languages, although at this point I have worked a lot with MATLAB/Octave code as well. In my case, it is very common that i-th element in an array is somehow related to say (x0 + i*dx). This fits naturally with 0-based indices. With 1-based indices you tend to have (i-1) or (x0-dx) everywhere. It gets extremely annoying when people get clever and rearrange this -1 in equations. Then it is no longer clear what is there as a side effect of the indexing and what is perhaps some constant in the numerical method.
- goatlover 10y agoI like Python a lot, but I find Julia's 1 based to be much more intuitive and easier to deal with.