News for hackers. Stuff that matters.
Re:Teal – A statically-typed dialect of Lua by ufo on Sunday October 18, 2026 @03:33PM (#50144503)
I find that in practice the amount of +-1 is about the same for zero-based and one-based indexing. Each has situations it is better suited for. For example, iterating a list backwards is nicer with one-based indexes.
Re:Teal – A statically-typed dialect of Lua by LoganDark on Sunday October 18, 2026 @04:34PM (#50145222)
I think it's inclusive indexing in general that make reverse iteration nice, not necessarily whether it's based on 1 or 0. (Namely, an ergonomic way to access the index of the last element as opposed to the length of the list. With inclusive indexing, the length is already naturally the index of the last element.)
Re:Teal – A statically-typed dialect of Lua by ufo on Sunday October 18, 2026 @07:33PM (#50146596)
For sure, but 0-based indexing often goes hand in hand with half-open intervals [0,n). One might even argue that a special way to access the "last index" is as unergonomic as just typing "length - 1"