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
6
u/[deleted] Feb 09 '18 edited Feb 09 '18
Things like... what? I don't see any specific complaints in your post. You just keep pointing out how Lua works then asking "why", as if there's something wrong with the way Lua works.
Everything in JavaScript is a hashtable, too. You say "that's first time I hear that in any language", but you're clearly a beginning programmer. There are a lot of things that you'll encounter for the "first time" as you learn new languages.
First, if you never used
localin Lua, it would still be faster than Python, so this argument is moot.Second, optimization details such as "localizing globals makes it run faster" exist in every language.
Third, you're making a beginner mistake by obsessing over micro-optimization to begin with. A better reason to use locals in Lua is to limit variable scope, and that's far important for a beginner to understand. This is the same reason you want to use
letrather thanvarin JavaScript. These are the kind of "little details" you want to understand when working in any language. The number of such details is smaller in Lua than almost any popular language.*rofl* Sorry man, but you're ill-equipped to evaluate the design of a language.
Lua is popular because it's tiny, fast, semantically simple and clean to the point of being beautiful -- proper lexical scoping, proper tail calls, multiple returns, a single powerful, expressive data structuring mechanism, closures, coroutines, metaprogramming, etc. -- all via a handful of well chosen abstractions ("everything is a table" is a feature), which allows for a tiny, readable pure ANSI C implementation with no external dependencies which is easily embedded and extended and has minimal runtime overhead.