I fell out of love with Lua

I used to like Lua a lot and now I don’t. I think anyone intending to add a scripting language to their game/engine should seriously consider using Javascript instead.

This opinion isn’t based on anything logical like speed or implementation. Lua has served us really well in Garry’s Mod in terms of both speed and speed of implementation. It’s worked pretty much flawlessly.

Syntax

My real issue with Lua is the syntax. It’s different for the sake of being different. A claim is always made that the language is made to be easy to understand. There’s a lot of places where this falls to bits. Want to add two strings together?

mystring = front + back;

No, that’s too hard to understand right? Lets do this instead.

mystring = front .. back;

Why is that easier for people to learn? Why are // comments harder to understand than — comments?

How do we test if something is not equal to something? Which one of these makes the most sense?

one ~= two
one != two

The ! isn’t used anywhere else on Lua, so there’s no real reason for them to use ~ other than to be contrary.

Bad Habits

By using Lua you’re teaching a bunch of people the wrong way to program. You’re teaching them a language that isn’t going to help them in the future. You’re teaching them that arrays start at 1 not 0.

Missing Features

Lua doesn’t have unicode support. This is a pretty big deal in a modern day scripting language, you shouldn’t have to treat strings like binary data and you shouldn’t have to install addons to support unicode.

No “var++” or “var += blah”. The whole point of scripting languages is to make it easier to code.

No continue keyword.

Javascript is the future

Javascript is used all over the web. It’s only going to end up getting used more and more. Google, Mozilla and Microsoft are all working to make it faster and faster.

Ultimately if we have to teach people a scripting language, lets teach them a language that will serve them in the future. Sure the jump from Lua to Javascript isn’t that great, but if you skip Lua there’s no need to make a jump at all.

86 thoughts on “I fell out of love with Lua

  1. I agree with the “Bad Habits” and “Missing Features” parts. But Javascript is certainly NOT the future, but the past. Even though Javascript is being “faster and faster”, it wont reach LuaJIT’s speed. Also javascript is missing some cool stuff such as metatables. And I really like lua’s “then” and “end” instead of {}, which makes the code smooth & clear, more “human”.
    I don’t know who told you that javascript is “the future”, but I would actually suggest to give him a rope and a stool for his birthday.

  2. The future is not Javascript. That’s like saying Ubuntu is the future of Linux. Some hipster will come out with a new language and other hipsters will jump onto it so they can learn it before it’s mainstream and be hip.
    Coding languages = real life languages. there is no “ultimate” language.

  3. @Dave I’m a hobbyiest programmer/game programmer with a uni minor in CS. I until very recently insisted that Python was the master race. Then I started work on two things: A complex timer (for game speedrunners) and a game. I felt like I was spending so much time fixing typing related errors and working with the weird inheritance and looking for libraries/reinventing ways to do things.

    The language I’m probably most familiar with besides Python is Java. I hated Java. The syntax is clearly inferior, the braces felt clunkier and harder to read than whitespace parsing, it lacks any elegant functional support. But then I switched the timer to Java for a cross-platform hotkey library. Suddenly the code became so much easier to write. Part of it is a better IDE (IDEA vs PyCharm), but a lot of it is that Java forces you to write correct code. Not elegant, not necessarily very readable, but correct. And this is the number one issue in getting large projects to scale up. I still hate Java, but it’s better than Python for anything of any size.

  4. Garry, I began by hating Lua, but now I’m in love.
    What really makes me love Lua these days is the metaprogramming, specifically metatables.
    It really is an agile and flexible little language, and it’s very close to Lisp.
    Everything you think you’d be able to do in Lua, you certainly can.
    Want to declare a variable’s value using a conditional? Sure thing!
    Want to do the equivalent of python list-comprehensions? Sure.
    Closures? No problem!
    Recursion? I do tail recursion easily!

    Javascript is as over-rated as node.js, it’s a fast language but it’s hardly elegant compared to Lua.
    You might like developing your own Lisp for RUST, it certainly would make things simpler when it comes to serialization. Hell, if you don’t, I will (as a mod that acts as a mod loader).

  5. I’m a professional software engineer. We have JavaScript that runs on the server side as well as client side. Have you even heard of Node.js? Use “===” to check type equality. It’s not that hard. Do you even code? Yikes.

  6. “This opinion isn’t based on anything logical like speed or implementation. Lua has served us really well in Garry’s Mod in terms of both speed and speed of implementation. It’s worked pretty much flawlessly.”
    What speed? Garry’s Mod is the slowest and most bugged game I ever played! I have to spend few hours to play it for 1 hour! Why I have to download addons that I have to play on server? (fully updated) It even causes Steam crash. Did anyone think about fixing it? Optimizing for slower computers? (last thing won’t work, played on computer 4x better than mine, still doesn’t work…)

  7. Sorry, but citing minuscule syntax differences as primary concerns about a language is probably the most moot criticism one could ever make. Pretty much only the lack of “var += blah” is the only valid concern, and even that is not a huge problem.

    Also, JavaScript’s broken comparison operators, lack of proper block scoping, and the fact that its prototypes are pretty much a gimped version of Lua’s metatables make it hard for me to find it as a better alternative to Lua.

    All in all, sorry, but I find it hard to take this post seriously.

  8. If you wonder why whitespace shouldn’t be syntax, you’ve never had a coworker who was visually impaired. That crap is terrible for him.

  9. Javascript is taking over the web, surely, but there are some thing that tick me off about it. The worst part I think is the way to create classes. Or rather how you _don’t_ create them – you create factories for objects.

    There are other things too, some of them can be pain, but most of them are just amusing :p

    Pics related:

    And to close off: http://puu.sh/geEw7.jpg

  10. Lost a lot of respect for you because of this post.

    Apparently you have no understanding of the history of programming language families. You say the syntactic choices of lua are inherently wrong without taking the time to grasp that lua is descended from ML-type languages, not C. Better call out the lisp’ers too, they must surely be programming the ‘wrong’ way.

    And recommending JS over lua? That is just laughable. Ever try embedding a JS engine? Ever even compiled one?

  11. Garry, you’re an idiot. Your complaints about Lua are utterly asinine and Javascript suffers from much worse, real issues like the fact that it moves code around in an opaque and offensive fashion.

    Honestly, I’ve never really expected many intelligent things to come from you. This post is reinforcing that belief.

  12. A few things:
    * Lua’s syntax isn’t different “for the sake of being different”, it just comes from non-C languages. (e.g. Modula, a dialect of Pascal)
    * 5.3 has UTF-8 support, but somebody already mentioned that.
    * Saying “It’s the future” is a shit excuse to justify anything. That crap is what made headaches like .NET and UEFI so popular.

  13. Lua silently returns nil for non-existent table slots, potentially propagating runtime errors far from their source, requiring external source analyzers. Its use of longjmp is incompatible with some automatic memory management systems.

  14. The worst thing about Javascript is its name, it misleads a bunch of ignorant morons and their mothers into thinking it’s somehow related to Java

  15. never got a headache with .NET
    works way better than java, better framework and WAAAY better VM, especially regarding memory management. The JVM is a pig.

  16. I once spent a week looking for a bug in a piece of JavaScript code that was caused by the + operator being treated as concatenation rather than addition. It thought 1 + 1 was 11. I like JavaScript, but using .. for concatenation in Lua makes far more sense; a strongly typed language like Java or something can get away with a + because everything is type-checked.

  17. I never once vouched that the JVM was better than .NET. I come from a low-level sysadmin background, so I never cared for either much. Classes being entry points makes me want to vomit, and while I don’t particularly dislike OOP, I hate it when languages promote it as some sort of end-all solution to every problem. That’s all just a matter of preference, though.
    But since you brought it up, I will say that .NET took the _one_ advantage of using precompiled bytecode on a process virtual machine and completely dragged it through the mud. The reason people I have talked to like Java (or more specifically, the JVM) is because binaries are cross-platform, and still have comparable performance. .NET takes that and completely destroys it by trying to make it Microsoft-exclusive. Sure, there’s always Mono, but it has always been a cut below the Microsoft implementation in every comparable aspect, not to mention being ridiculously slower on non-Windows systems.
    Since I’m commenting, I should probably mention that Modula isn’t technically a “dialect” of Pascal, but I think anyone with Google could’ve inferred that much. Also, there are plenty of languages that have 1-based arrays; Smalltalk and Fortran, for instance. (inb4 “Fortran is a dead language hurr”) And even then, you can still _assign_ values to 0. Thinking of Lua’s arrays as the same as arrays in languages like C is a vast misunderstanding of the language itself.

  18. A lot of the reasoning for Lua seems to come from Matlab and Fortran (1 based arrays, loop syntax, string concatenation), but there is a lot of Lisp concepts too (recursion, anonymous functions). Lua was originally used in control systems for industrial plants, when there were export restrictions on US products.

    If you’re target platform is only the desktop or server, then there are other languages better suited. But for embedding in a game or microprocessor, Lua has strong points.

  19. All your points aren’t much important to me, though I think that Lua is awful, too.. as well as JS
    Array indexing, string concatenation isn’t the issues for me

    Much bigger issue to me is
    – damn freedom everywhere
    – no way to simply look what arguments some imported function accepts
    – not obvious, write-only code
    – global, uncontrollable state a one can add ANYWHERE

  20. I know this is old but… Garry… why :(

    Javascript has so many quirks it’s literally a step up from reading assembly or the obfuscated mess that is most Haskell code.

  21. Lol your a fool right off the bat. In JavaScript you often need to add numbers in the format of var1 -(var2*-1) so that it treats it as a non string. Fool.

  22. To be fair, you can write it like that in lua too:

    function lol(cake)
    (cake == somecake and die or yay)()
    end

    lol “lolz”

  23. If you’re doing string concat frequently, like in a tight loop, you wouldn’t use the concat operator like this because it’s inefficient since strings are intern’ed and immutable. You would use table.concat and table.insert for this.

  24. All of “bad” design decisions Garry is bitching about could be flung right back at all of the mainstream C- descended languages.

    // is ugly. != has no grounding in math theory, unlike ~=. Humans think lists start at 1, not 0. Concatenating strings with + is ugly.

    I think this quote solidifies how moronic this post is. Right under the title JAVASCRIPT IS THE FUTURE, “Javascript is used all over the web.”

    If I had to write in JavaScript instead of Lua to make addons for GMod, then I probably wouldn’t have gotten into coding. Thank you Garry, for making that mistake.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s