Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> One way to think about "tables" is that they have an array part and a hashmap part.

But why conflate the two? There's no benefit to this, only drawbacks.

> The # operator works on the array part simply starts counting from the first index and stops counting when it reaches nil.

That's obviously not the case, as can be seen from #a returning 4 after setting a[4] = "w", even though a[2] == nil. There's no simple logic behind the # operator's behavior, it's an unintuitive mess.

> Your complaints sound a little bit like you wish Lua was a little bit more, but it kind of has a design goal of being simple language you can embed.

No, a simple language doesn't have to be inconsistent.



> No, a simple language doesn't have to be inconsistent.

Sorry I meant to say minimal and I was referring to the lack of certain features , not necessarily simple which is something else.

> That's obviously not the case, as can be seen from #a returning 4 after setting a[4] = "w", even though a[2] == nil. There's no simple logic behind the # operator's behavior, it's an unintuitive mess.

Oh, so perhaps it's a combination of being an "unintuitive mess" and/or it's been changed and/or I don't even remember.

Running the code you provided in the Lua online demo (which is lua 5.4.6) yields 3,3,4,4,3 so I guess you were running an older version.

I don't think this is a big problem in practice if you are just aware of this. It's a bit like 1 vs 0 based indexing. It may have been a problem in the beginning but it's been too long since I first started using Lua. And here you'd have a point.

> But why conflate the two? There's no benefit to this, only drawbacks.

I honestly don't know. I'm actually more on your side when it comes to distinguishing arrays and tables. I just don't think it's as big of a deal as you make it out to be.

-

As I alluded to earlier, you can just change Lua to fit your needs. It's meant as a language you embed in your own framework and was never really meant as a fully standalone language as far as I understand. Its position of being standalone is kinda weak in my opinion.

You even mentioned previously that "Lua is supposed to be a scripting language with a REPL" but the REPL included is the bare minimum.

By far my own biggest "complaint" about Lua is that it's dynamic. However Lua with types would be a different language entirely.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: