3 ms·
This. The insistence on using 0-based string offsets is purely a C thing (where it makes sense) inherited on to languages that wanted to stay close to C or appe
by tannhaeuser 5y ago
This. The insistence on using 0-based string offsets is purely a C thing (where it makes sense) inherited on to languages that wanted to stay close to C or appeal to C devs (even though it does not make sense). An easy way to check is looking into awk which, as a DSL for string manipulation written itself in C, deliberately uses 1-based string offsets, and where many/most common string expressions collapse to a very compact form, which makes even more sense because empty string results are interpreted as false in conditions.
- jhvkjhk 5y agoIt's not a C thing, it's a math/utility thing. Dijkstra: Why numbering should start at zero https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- corysama 5y agoWhich is funny because Lua got it’s 1-base from FORTRAN which, I believe, adopted it to make TRANslating math FORmulas easier.
- tovej 5y agoI agree in part that it's a C thing. More accurately it's an offset from the array base thing. The first element is at index 0 because its address is base + 0 * sizeof(element) The second element is at index 1 because its address is base + 1 * sizeof(element)