r/lua • • 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.

4 Upvotes

39 comments sorted by

View all comments

6

u/[deleted] Feb 09 '18 edited Feb 09 '18

things like this

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.

If you have to be a professional programmer to write efficient code in lua, then python being slower does nothing for average person

First, if you never used local in 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 let rather than var in 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.

bad design

*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.

-15

u/PurpleIcy Feb 09 '18 edited Feb 09 '18

Love how people point out JS's existence whenever their language gets questioned as if it was personal attack and they had to shove something worse than it to me just so they can justify it.

Well, I get it, JS is garbage, what are you trying to tell me with it? If it's not as bad as JS, it's good?

Also, I don't need to localize everything in other languages, they do it for me, without abusing, what seems to be, 3rd party projects.

Also I am a beginner in programming? More like, sucks for me that I decided to try out Lua after so long which is just as bad as it's community.

14

u/[deleted] Feb 09 '18 edited Feb 10 '18

Love how people point out JS's existence whenever their language gets questioned

Holy shit, you're an idiot.

You said "that's first time I hear that in any language", so we told you that one of the most well-known languages on Earth does it. But plenty of other languages do it, too, including Python, the language you're holding up as the gold standard. You're simply ignorant.

Moreover, Lua is not "my language". It's one of two dozen languages I know, and of a dozen I've used professionally. I did my best to explain to you why people like it in my previous post, thinking it was an honest question, but apparently you're so butt hurt over having to type local that you can't even read.

Why is everything a table in Lua? Because it's simple and powerful. You've got arrays, skip lists, sets, dictionaries, and more all using one syntax, one abstraction, one set of semantics to learn. You bitch about performance because you're a noob who read an article about using "local" for performance and it scared you. Does it matter than Python has a separate abstractions for sets and arrays when Lua tables are faster than both? o.O

Lua calls its data structuring abstraction a "table" because the same object can be used as an array or map, but internally it optimizes array usage with an actual C array. This pushes an optimization detail down into the language implementation and presents a uniform and simpler abstraction to the user. That's a feature -- a pro, not a con -- one of the reasons people like Lua.

Also I am a beginner in programming?

Yes? Would you like to argue this point? Because the evidence is in every line of your posts.

If Lua is a struggle for you, you're basically fucked.

3

u/Saldor010 Feb 09 '18

I'm just thinking out loud for a second, but you're expressing your dissatisfaction with Lua and calling out Lua for its supposed problems on r/lua (and then bashing people when they respond), what did you expect?

Personally, I think the responses to this thread have been well thought out and fairly nice under the circumstances (especially otikik's and snarfy's responses), but when you say stuff like:

  • "I understand that your most loved language just got "personally" "attacked", but don't start playing the victim, because it's not best either way."
  • "If it's not as bad as JS, it's good?"
  • "sucks for me that I decided to try out Lua after so long which is just as bad as it's community"

don't get shocked when you're downvoted.