6 ms·
Why? From one of Roberto Ierusalimschy's talks (starts at slide 6): http://www.inf.puc-rio.br/%7Eroberto/talks/ws2011.pdf http://www.inf.puc-rio.br/%7Eroberto/
by ewmailing 10y ago
Why? From one of Roberto Ierusalimschy's talks (starts at slide 6):
http://www.inf.puc-rio.br/%7Eroberto/talks/ws2011.pdf http://www.inf.puc-rio.br/%7Eroberto/talks/ws2011.pdf
Excerpt:
- Not all languages are 0-based: Icon, Fortran, AWK1, and Smalltalk are 1-based; Snobol, Pascal, Modula, Modula-32, and Ada have configurable bases.
- Currently, many languages are 0-based due to influence from C.
- Ironically, none of them share the reason that made C 0-based (where a[e] means *(a+e)).
1-based arrays:
- Much more intuitive: first is 1st (not 0th).
ISO-C: “E1[E2] designates the E2-th element of E1 (counting from zero).”
- Much easier for non programmers. Easy for (good) programmers :)
- Historical reason: Fortran used 1-based arrays, and most first users of Lua had a Fortran background.
- kbd 10y agoThe presentation asserts that 0-based arrays have "More interesting mathematical properties". Dijkstra's classic paper on this is a must-read: http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF