5 ms·
A contrary view, just to be fair and balanced. I really didn't enjoy using Lua, though it had its moments. A. Lua's source code is pretty inscrutable, and writ
by to3m 12y ago
A contrary view, just to be fair and balanced. I really didn't enjoy using Lua, though it had its moments.
A. Lua's source code is pretty inscrutable, and written in a style that was pretty alien to me. It was also a bit horrid to single-step through because of all those damn reference copying macros. But it's actually fairly easy to add stuff to it and modify it, and this was what actually convinced me to go with Lua in the end; look-mummy-my-first-Lua-hack was surprisingly easy to put in.
B. Lack of variable declarations and global-by-default was a terrible idea. Languages should require declarations, or at least be local-by-default, and have a special interactive mode for when you want the no-declarations-and-global-by-default behaviour. Because making things "convenient" is fine, until it isn't, at which point it just becomes a bug magnet. For a language supposedly designed for use by people who don't know what they're doing, this borders on criminal; when you've got years of experience behind you, it's merely a huge pain in the arse. MaxScript gets this wrong too.
C. 1-based indexing is annoying. If it makes no difference, switch to zero, because it's then the same as other languages; if it makes a big difference, switch to zero so that it isn't so difficult. Just because you can switch back from one way of doing things to the other doesn't make 1-based indexing right! MaxScript gets this wrong as well. But 1-based indexing would be wrong even if MaxScript and Lua didn't do it.
D. Lack of a proper array type is silly; you have this ugly thing that's like an array, but not, and it's easy to stop it being like an array. Because it's not an array... it's a mapping. A mapping with some very odd ideas. Come on people, mappings and sequences aren't the same! Shape up!
(At this point in my argument I used to be in the habit of adding, "after all, you wouldn't skip having separate integer and floating-point types, now, would you?" - because Lua famously had just the float variety. But these days they have integers too. So I'm still in the habit of adding it.)
(The Lua guys' insistence on minimizing number of data types can also be seen in the lack of a separate symbol type. Even MaxScript doesn't get that wrong.)
E. The C-side API is actually kind of weird, but on the plus side it's actually somewhat difficult to use improperly from C. So... I guess that's even. Maybe there shouldn't even be a point E, but... well. The C-side API really does stick in my mind.
Aside from that, no complaints!
(This post is at least partly just so that other people who don't like Lua know that they aren't alone.)
- ufo 12y agoVariables being global by default is definitely a wart. You can mitigate it a lot with a linter or with runtime tests (extending the global metatable). Local by default would be a bad idea and worse than global by default, IMO, as it would mess up lexical scoping. The ideal would be having a compilation error by default.
- to3m 12y agoIt would be fine, I think. Just create the variable in the scope you want it, then assign to it somewhere else. If you get it wrong, you get it wrong, and there's scope for weird bugs from that - but the effect is at least localized, lexically. (Of course, the right thing to do is have explicit variable declarations...)
- ufo 12y agoLocalized bugs are still bugs. Better always require a variable declaration and have no defaults. Usually languages use local-by-default to avoid the need for variable declarations in the first place (in misguided manner, IMO) instead of doing so to avoid globals. This page might be interesting, btw: http://lua-users.org/wiki/LocalByDefault http://lua-users.org/wiki/LocalByDefault
- _paulc 12y agoYou should have a look at Squirrel (http://www.squirrel-lang.org/ http://www.squirrel-lang.org/) - it addresses most of the points above but is still very lightweight and easy to embed. The main disadvantage is that the documentation and community is not as well developed as Lua.
- anonymoushn 12y agoWhat's the symbol type for, and is Lua incapable of expressing it?
- ufo 12y agoSymbol types[1] are useful for storing identifiers, method names or enums. They are common in LISPs and in Lua you use (immutable) strings for a similar purpose[2]. The main advantage of symbol types are that they have a more restricted API than strings and that they might be more efficient (integer vs string representation) [1] https://en.wikipedia.org/wiki/Symbol_%28Lisp%29 https://en.wikipedia.org/wiki/Symbol_%28Lisp%29 [2] For example, in Lua obj.foo is syntactic sugar for obj["foo"], similarly to Javascript.