10 ms·
What's bad about pairs/ipairs? They're just iterators, and they make the "generic for" construct much more versatile. The standard library also includes two m
by groovy2shoes 13y ago
What's bad about pairs/ipairs? They're just iterators, and they make the "generic for" construct much more versatile. The standard library also includes two more iterators, string.gmatch() and io.lines(), which are pretty handy. I've also used iterators to implement streams (or "lazy seqs", if you will) and something akin to Python's range().
I find nothing weird about lexical scope and the 1-based arrays don't bother me at all, but iterators are awesome.
To me, Lua's most annoying feature is that tables are the only data structure. When I was first learning Lua, I thought it was pretty cool to have one and only one very versatile data structure. Nowadays, I find it's more trouble than it's worth. Indeed, the fact that pairs() and ipairs() are separate functions demonstrates that tables are a leaky abstraction: you have to constantly think about whether a table represents a hashmap or an array or both. Luckily, Lua is very extensible and there are several ways around it.
All in all, I find Lua to be an excellent language. I wrote a utility in it at work, and most of the veterans started sweating when I told them it was written in some language they'd never heard of. As soon as I showed them the code, they were visibly relieved. "We can read this and understand it," they said. Lua's readability is a big win.
- ansible 13y agoTo me, Lua's most annoying feature is that tables are the only data structure. When I was first learning Lua, I thought it was pretty cool to have one and only one very versatile data structure. Nowadays, I find it's more trouble than it's worth. To me, this harkens back to the debate about the length of a table if it has nils in it. The Lua table is not the be-all and end-all of data structures (though it is quite versatile out of the box). However, it can be the basis for any kind of data structure you can imagine. Trees of all varieties, priority queues, etc.. The strength of the language is that there is just one fundamental data structure, and it is implemented well, and it has good syntax support in the language. There is no mental overhead like with Python where you have to use square brackets for lists and curly braces for dictionaries.
- nimble 13y ago> There is no mental overhead like with Python where you have to use square brackets for lists and curly braces for dictionaries. Seriously?
- kazagistar 13y agoHe forgot to mention objects, which are also almost-dicts in python, but with a ton of magic rules like slots and methods storing their object when assigned and whatnot. Lua has pretty nice and lightweight prototype OOP, which boils down to a few uses of : instead of . on tables and setting the __index of the metatable to be the parent table. That's not to say python is not an excellent language, just that lua is a lot simpler.