Re: Found on HN: Again on 0-based vs. 1-based indexing
- Posted by petelomax Jan 22, 2021
- 1681 views
Another detailed attempt: http://enchantia.com/software/graphapp/doc/tech/arrays1.html
Concludes with "no clear winner", except for interoperability.
(Dunno about you, but the occasional -1 on the odd c_func() just doesn't really bother me anymore.)
The following languages use 1-based indices: Algol, AWK, COBOL, Euphoria, Fortran, Julia, Lua, Pascal, Phix, Smalltalk
The following languages allow negative indices: Perl, Phix, PowerShell, Python, Ruby
(Dang - I keep on posting this without saying what I came here to say...)
In a language with both 0-based indices and negative indices, apart from the disjoin of a[0] rather than a[1] as first vs. a[-1] as last,
there is no sensible value that eg find() can return that is a non-functional index, whereas in Phix, find() can return 0 and that won't accidentally retrieve the wrong element.

