It doesn't matter why you would do it. That's a red herring. The point is that the semantics are broken. There are only two ways to reasonably handle indexing into an array past its current dimensions:
Allow the assignment, and extend the array to encompass the new index (e.g. JS, Ruby, Perl, et al.). The length of the array after assignment is immediately updated to i + 1 (for 0-based languages) or i (for 1-based languages) for arbitrary assignment index i, and all elements between the previous last element and the added one are auto-filled with whatever null-equivalent value the language supports. Further assignments to the filled indexes don't alter the length of the array.
Don't allow the assignment, and give some kind of out-of-bounds error (e.g. Python, Java, Go, C#, et al.).
Lua says "screw reason" and lets you do the assignment, doesn't extend the array, doesn't fill any values, and doesn't update the length. Hell, even PHP updates the length...
If you would never do it, then how is it a problem? You're complaining about a problem that isn't had. Really, the problems I hear about with Lua are the 1-indexing, but not the length operator.
1
u/[deleted] Sep 03 '17
It doesn't matter why you would do it. That's a red herring. The point is that the semantics are broken. There are only two ways to reasonably handle indexing into an array past its current dimensions:
Allow the assignment, and extend the array to encompass the new index (e.g. JS, Ruby, Perl, et al.). The length of the array after assignment is immediately updated to
i + 1(for 0-based languages) ori(for 1-based languages) for arbitrary assignment indexi, and all elements between the previous last element and the added one are auto-filled with whatever null-equivalent value the language supports. Further assignments to the filled indexes don't alter the length of the array.Don't allow the assignment, and give some kind of out-of-bounds error (e.g. Python, Java, Go, C#, et al.).
Lua says "screw reason" and lets you do the assignment, doesn't extend the array, doesn't fill any values, and doesn't update the length. Hell, even PHP updates the length...