Lua: the world's most infuriating language?
slideshare.net
slideshare.net
I mean, 1-based arrays, weird scoping and the pairs/ipairs thing seems far more serious than the lack of a proper conditional operator (how long did Python go before it got a conditional operator?)
Lua is everything it was meant to be - a lightweight, user-friendly, safe language that runs nice and fast in spite of being very hashtable-oriented. There's a good reason it's heavily used as a scripting language for game engines and other platforms that need to let users run code provided by other users - a more "batteries-included" language would have users wiping each other's filesystems.
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.
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.
Seriously?
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.
1-based: you're numbering. In Lua, an array is an optimization of a hash, and the items inserted without explicit keys are numbered one, two, three…
What you consider a minor gripe, compound assignment operator, I personally think is a flaw in the language same goes for bitwise functions instead of operators. Here is an example I posted earlier on twitter.
object = object + other
"object" and "other" here are full userdata and the code is going to malloc a new userdata and also create a new object in C/C++; which is straight away going to over write the original instance. Huh? why? += makes so much sense.
Each to there own, I can fix my issues using patches but it would be nice if I did not have to.
t = {foo()}
And now with 0-based indexing: function capture_values_internal(idx,t,remaining,val,...)
if remaining == 0 then
return t
else
t[idx]=val
return capture_values_internal(idx+1,t,remaining-1,...)
end
end
function capture_values(...)
return capture_values_internal(0,{},select("#",...),...)
end
t = capture_values(foo())
or function capture_values(...)
local n,t=select("#",...),{...}
for i=0,n do
t[i]=t[i+1]
end
return t
end
t = capture_values(foo())
Gosh, that was easy, I can't wait to use 0-based indexing throughout my program.No. Not having a real numeric or array type is serious, '1-based arrays' is just a minor quibble about syntactic sugar.
There's also the history of development. Lua has always been an embedded language and the Lua team have always had an eye cocked to size and speed.
Finally, size. The Lua runtime is tiny, these days it fits into an L2 cache. If your program doesn't have a lot of data, the effects of cache locality may give you tremendous speedups.
http://docs.python.org/2/reference/datamodel.html#special-me...
Python's standard methods of creating new objects off common operations also leads to huge amounts of memory being used compared ('functional programming' to use the term of the moment) to Lua's more c-like mutate-in-place standard behavior.
Basically pretty much anything not from __builtin__ or from a C extension is entirely mutable at any time. Consider one of the problems PyPy had with some packages. PyPy didn't support `locals()[42] = value`, which some packages actually depended upon. Nor does PyPy support `instance.__dict__[42] = value` which even more depended upon. Generally Python used a lot of simple concepts such as mutable dictionaries with heterogeneously-typed keys as the implementation of how classes, modules, etc works, which is flexible but very hard to optimize in any way (especially since they are mutable).
In contrast, the Lua developers always cared a lot about efficiency, not just speed, also memory use, and even GC pause times. They simply have different priorities than the CPython developers.
Of course, bad designed language in terms of performance will suffer more to get into the state-of-the-art
Maybe instead of trying to use lua as another language, you should totally embrace "the lua way" and then you'll understand why their tables/metatables is the way it is.
It's basically Lua, with his complaints fixed.
Sure there are warts, such as the lack of "+=" or "++", but once you get into the right state of mind it is a pleasure to work with.
Congradulations, you have metaprogrammed lua to only set globals explicitly. Good job!