lots of people complain about it being really weird for various reasons, but these are generally superficial
or using
do
..end
style blocks instead of{
..}
, which again is just a syntax choice and does not impact programming that muchit’s a tad bit more line noise, but not that terrible. I did design a language using
do
..end
blocks and it really doesn’t look that bad
but I think Lua is a pretty damn genius programming language.
the use of tables as The One Data Structure for Literally Everything strikes me as a 200 IQ choice I could never come up with myself
tables are extremely powerful in what they can do, because they’re more than just a way of structuring data - they also allow for interfacing with the language syntax through operator overloading
in fact object oriented programming in Lua is typically done by overloading the
[]
indexing operator.the way it works is that
a.b
is just syntax sugar fora["b"]
, which means you overload[]
to fall back to another table - and that way you can achieve prototype-based inheritance!local fallback = { b = 2 } local base = { a = 1 } -- The __index field can be both a function *and* a table. -- { __index = the_table } is a shorthand for { __index = function (t, k) return the_table[k] end } setmetatable(base, { __index = fallback }) assert(base.b == 2)
there are also some bits of syntax that haven’t aged very well.
as much as people complain about cosmetics [TODO: link], I think there’s a particular design choice that has aged very poorly in the face of modern, functional programming - function literals.
these tend to be quite verbose in Lua which hurts readability in functional code:
local u = map(t, function (v) return v + 2 end)
compare that to JavaScript’s arrow functions
=>
, which I think are a prime example of good syntax sugar that encourages more function-oriented programming:let u = t.map(v => v + 2)