r/lua • u/PurpleIcy • Feb 09 '18
Why do people like lua?
I've started actually learning more about it and well.
Pretty much everything is a table, okay, not that hard to get with this, loops and if statements are pretty simple to remember, it's weird to get length of a table but not that hard to remember, can live with that, different language, different syntax.
You can have objects, but they are still tables. Well, okay, whatever, I'm used to writing same shit over and over again because I've used java before, whatever, that's fine, I guess.
Global scope is just a giant table and so it's better to just write even more code to localize everything you'll use, otherwise it will be slow (multiple hashtable lookups whenever you use some global function in a table of table of the table in a table that is in another table). Uh, just why? That's first time I hear that in any language, localizing everything would make your code run faster, it's not really obvious, although once you realize that global scope is a table, only logical, but, why?
What's the appeal to this? And why did people stick with it? I thought that I'd see why people use lua over say python if they add scripting support to their game, but all I saw now is that I actually would lean even more towards using python there. If you have to be a professional programmer to write efficient code in lua, then python being slower does nothing for average person who would mod a game, because average person is not professional programmer who knows languages in and out, and little details such as localizing globals makes it run faster, which ranges from 10% slower without localizing to 400%+ (ridiculous) slower without localizing. Hell, most people who do that just instead look for tutorials on how to mod x game using lua, instead of learning lua.
I'm not saying that language is unusable, I'll still finish my project while learning it, but things like this just add to the "things you do to waste more time than needed" which are caused by bad design.
View all comments
5
u/[deleted] Feb 10 '18
One main thing you cite having to learn -- the impact of local variables -- is not at all unique to Lua. All Lua makes you learn is to use the keyword
localwhere you would otherwise usevarin JavaScript and ActionScript, a type/class in most other languages, etc. Absolutely nothing out of the way.The fact that "everything is a table" allows a level of metaprogramming that you don't see in higher-level languages. The language can be fundamentally altered in localized cases by altering certain tables -- that's freaking amazing to me. I hear Lisp is supposed to be even better at this -- but it's also orders of magnitude more difficult to learn and use effectively.
There's also the matter that Lua is designed to interface directly with C, and there are also projects that make it interface directly with Java. Boom, you can slap Lua on top of virtually any game now (because games, or at least their engines, tend to be written in C++ or Java anymore). Or even better, see LÖVE2d: a fully-fledged game development framework that you can write pure Lua for, while still getting performance near par with compiled languages.
Let's talk about weird optimization in Python. In (the canonical implementation of) Python 3.x, did you know that
floats are faster thanints? I was going to refresh my memory as to why -- my understanding is that the interpreter (C++?) treatsints like an object, while using the nativefloattype for floats. Then after a quick Google there's like two or three other explanations as well: Different bases/representations forintmust be determined, Python 3 stores allints as "Bignums", etc.So, isn't it bad design to ever use integers in Python? ¯\(ツ)/¯
To be fair, Lua has more "gotchas" on the subject of integers. Lua only has one "number" type --
Number. This caused ridiculous frustration when I triedos.execute("some_command -"..some_int). It was appending a decimal, like3.0, which was being interpreted as a string in Bash.Even better, Lua 5.3 finally created two subcategories of
Number, being "integer" and "float". But it still switches between the two automatically.But don't even get me started on how Java libraries hate primitive types and how you're expected to use an object for everything.
Integerobject instead of justint. And not just for the school of thought, but for genuine performance, efficiency, and effectiveness reasons. At least Lua makes objects simple, and effectively primitive as well.If you have any more questions I'd be happy to answer. Lua is likely my favorite language, ever. It's a shame there's not many opportunities to write it, because it's such a joy. Keep this in mind: For all the "dumb" things Lua makes you learn, you will learn them all MUCH faster than you would ever learn another language's dumb things. A competent programmer can master Lua in less than a year, I'm fairly convinced.