3 ms·
Dijkstra had an opinion on this (and many other things). 0-based ftw. https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF https://www.cs.utexas.edu/users/EW
by verytrivial 3y ago
Dijkstra had an opinion on this (and many other things). 0-based ftw.
https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF
- teamonkey 3y agoBit short-sighted of him to only consider positive array indices IMO. Lua allows them to be negative.
- bdowling 3y agoLua also allows floating point indices. In fact, any value can be an index into a table. That means any number, string, True/False, function reference, thread (coroutine) reference, table reference, "userdata" reference (usually a pointer to a C object), or nil can be an index.
- bdowling 3y agoCorrection, any value except nil can be an index into a table. https://www.lua.org/manual/5.3/manual.html#2.1 https://www.lua.org/manual/5.3/manual.html#2.1
- ufo 3y agoDijkstra conveniently ignored the other situations where 1-based works out better than 0-based. For example, getting the least element of the array, or iterating backwards over the array.
- PedroBatista 3y agoThis reminds me of that somewhat famous observation about the bright scientists working to increase clicks at Google/FB instead of finding cures for diseases and such. So much brain power to defend something that existed a long time ago and was adopted as some kind of law of the Universe when there is clearly no good reason to be this way today other than "it's just how it is" and every new programmer has to pass for a quick phase where the 1-based it beaten out of his mind.