Comment by teo_zero
1 year ago
> [0-based indexes] are a relic of C style arrays
I don't think this is true. They exist in other disciplines (maths for instance) that have no relationship with C or other programming languages from the 1970s.
> for 0 to count/len/num - 1
I will counter saying that such a for...to syntax is a relic of BASIC.
> or even better range syntax that is start inclusive BUT end exclusive
I know that your "better" is sarcastic, but I actually find left-inclusive+right-exclusive ranges fantastic. They allow perfect partitioning, easy calculation of lenght, etc.
> Arrays should start and end at whatever start index is required
I agree. An accommodating language would let you define both lower and upper bounds of an array, instead of its size.
IIRC some BASIC(s) I've used in the past had a statement called:
OPTION BASE 1
or something like that, to change the starting index to 1.
APL has ⎕IO←0 or ⎕IO←1 to change the starting index (only between 0 or 1, not arbitrarily). It doesn't apply system-wide so different code blocks/files/modules(?) can set or reset it, and portable code has to either set it or adjust for it.
APLCast podcast has an episode mentioning it where they all seem to agree that this is the worst of all worlds, makes sharing code and integrating codebases needlessly bug-prone, and the language picking a single indexing and sticking to it would have been better, even if the choice hadn't gone the way they would have personally chosen.
Interesting. Never used APL, though I tried J a little a few times.
Yes, that seems bug prone, somewhat like having to have a config file per module.