"C arrays are zero-based, so the indexes have to run from 0 to n-1. One might want to allocate one more element instead to simplify converting legacy code."
I am not a Lua programmer, but if most of the languages you will interface with are 0 based such as C, it seems like an unnecessary worry to use 1 based
I read this twice and still couldn't make heads or tails of it.
Maybe because I learned programming in BASIC, and some variants of BASIC support 'Option Base (0|1)'?
Or had to port 1-based Algol code to 0-based Python?
Algol, of course, is usually compiled to machine code while CPython, like Lua, compiles to bytecode. And Algol allowed you to specify your own base, with "LWB" and "UPB" as a way to get the lower and upper bounds without needing to know the index.
Similarly, perl back when I used it let you set '$[' to change the array base index.
I don't know how to characterize all of those languages and people along the simple axis of "borders" and "no-borders", and the author didn't explain how that axis works. I also read https://github.com/a327ex/blog/issues/66 and still am unenlightened.
2 comments
[ 3.0 ms ] story [ 12.1 ms ] threadFrom https://luajit.org/ext_ffi.html
I am not a Lua programmer, but if most of the languages you will interface with are 0 based such as C, it seems like an unnecessary worry to use 1 based
Maybe because I learned programming in BASIC, and some variants of BASIC support 'Option Base (0|1)'?
Or had to port 1-based Algol code to 0-based Python?
Algol, of course, is usually compiled to machine code while CPython, like Lua, compiles to bytecode. And Algol allowed you to specify your own base, with "LWB" and "UPB" as a way to get the lower and upper bounds without needing to know the index.
Similarly, perl back when I used it let you set '$[' to change the array base index.
And there's Dijkstra's famous essay on the topic, at https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
I don't know how to characterize all of those languages and people along the simple axis of "borders" and "no-borders", and the author didn't explain how that axis works. I also read https://github.com/a327ex/blog/issues/66 and still am unenlightened.