4 ms·
From an aesthetic perspective, I agree. In practice, it wasn't a problem, though. I rarely accessed arrays with a constant index anyway.
by krylon 3y ago
From an aesthetic perspective, I agree. In practice, it wasn't a problem, though. I rarely accessed arrays with a constant index anyway.
- bryanrasmussen 3y agomaybe I'm being dim but what possible aesthetic benefit does it offer? The only benefit that springs to my mind from a language design perspective is that it is most likely familiar to the user of the language from languages they have used before. Both Smalltalk and APL use 1 based indices so I just find any claim of obvious aesthetic superiority on this issue a little hard to accept without some back up. If speaking aesthetics the fact that the number of items in your array is equal to the position of the last index item in the array would seem aesthetically superior.
- ufo 3y agoLua's 1-based indexing is largely inspired by Fortran. Lua's first users were Brazilian engineers in the early 90s, who were mostly experienced in Fortran. Arguably, one-based indexing is more closed aligned to mathematics tradition. That point about being easier to index the last element helps to iterate backwards over an array. With zero-based indexing, a backwards loop becomes for(i=N-1; i>=0; i--). Yuck.
- bryanrasmussen 3y agoexactly, I have a hard time understanding any argument for 0 based indexing other than tradition or a performance hack that I find unlikely was ever that great a benefit anyway.
- taylorius 3y agoIt is admittedly a mindset that is born of C coding. Pointers and memory offsets and so forth. But lots of languages that abstract such "close to the metal" factors away, still use 0 based indexing.
- krylon 3y agoI meant that aesthetically, I find 0-based indexing more appealing.