ok, new rule:

anyone who thinks python's "passing a negative index into an array gives you an item from the end of the array" system makes sense is allowed to complain about lua indexing arrays from 1

@andrewt does it help knowing that lua doesn't have arrays and you can index tables with whatever you want, including the number 0?

@mavica_again I mean that would help if it was meaningfully true, but it's not really, it is?

Basically all modern programming languages have something that's equivalent to and array and something that's equivalent to Python's "dict", and the fact that in Lua both of those are "table" is of monumental irrelevance to anyone actually *using* Lua.

If I type "a = {1, 2, 3}" into Lua I get an array indexed from 1. If I type "#a" into Lua it tells me the number of consecutive numbers that are valid indices of "a", starting from 1. Lua has a built-in implementation of arrays that is supported directly by specialised syntax. And it indexes them from 1.

Follow

@andrewt well i wasn't trying to be too serious :blobtongue:

personally, i think python's negative indexing (and slicing!) is extremely useful and i grok that lua's index-from-one stems more from historical reasons (and i prefer to be able to use rather than -1 to get to the last element of a list)

@mavica_again Yeah, t[#t] is nice, but equally I think lua has no "append" function so t[#t+1]=x is just as annoying as t[#t-1] would be.

As far as I'm concerned, Lua indexing from 1 and Python's negative indices are the same problem: they prioritise readability with literal indices (of course t[1] isn't the *second* element; of course t[-3:] is the last three elements) over usability in complex programmes (t[i%#t] doesn't work in Lua, and t[centre-3:centre+4] doesn't work in Python), and this annoys me because "deep in a complex program" is when I am *least* able to deal with this nonsense.

JavaScript might be harder to just noodle about it, but the moment you start writing complicated functions, it does at least behave like a reasonable person would expect, which is really not true of either Lua or Python.

@nullifidian @mavica_again seems to be "table.insert" from a bit of googling, but ok, yes, that does exist. a bit clunky but clearly extant.

Sign in to participate in the conversation
Computer Fairies

Computer Fairies is a Mastodon instance that aims to be as queer, friendly and furry as possible. We welcome all kinds of computer fairies!