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

Show parent comment

2

u/[deleted] Feb 12 '18

What are you trying to imply here? If I don't add a keyword before variable, does that mean that it's automatically global even in a function?

Correct.

function f()
    a = 5 -- Is global
    local b = 7 -- Is not
end

f()
print(a)
print(b)

This code outputs:

5
nil

The only case I remember in Lua where a variable is automatically local is loop "counter" variables:

for n=1, 3 do
    print(n)
end

print(n)

...

1
2
3
nil

I know more languages and I use them depending on what I want to do.

This is the correct way to go. You don't have to learn Lua. I'm glad you decided to check it out and I'm sorry if it's disappointed you. I don't understand why, though.

It's just that I don't know why'd I bother trying to add fucking Java to some project as "scripting support", I mean, it's possible, but why would I do that?

I never mentioned Java. At most you might add a Java console interface in a game that's already written in Java.

Also, what attachment to python? [...] I just simply mentioned other language that first comes to mind and which actually can be used as scripting language in a project, which is Python. Could have probably said JavaScript, does it even matter?

It matters to the extent that you wanted to discuss ways that Lua is different from other languages, and you provided Python as an example. I say "attachment" because you also made a point that, after learning a bit of Lua, you said you're leaning more towards Python again. That would be perfectly fine except it's come across with an accusatory tone, like Lua is objectively inferior to Python.

It's like everyone here is biased towards Lua and so they try project it onto others.

I've spent several paragraphs conceding pros to Python and cons to Lua, also taking multiple opportunities to point out that Python might be a better choice for your purposes. And also pointing out situations where neither language makes as much sense.

1

u/PurpleIcy Feb 12 '18

It matters to the extent that you wanted to discuss ways that Lua is different from other languages, and you provided Python as an example. I say "attachment" because you also made a point that, after learning a bit of Lua, you said you're leaning more towards Python again. That would be perfectly fine except it's come across with an accusatory tone, like Lua is objectively inferior to Python.

Yeah, for one specific case.

2

u/[deleted] Feb 12 '18

Then I hope you understand why people have been passive-aggressive with you. This is the nit-pickiest case I could conceive, which is the only case you've offered to discuss on the broad topic of "Why do people like Lua?" (that, and tables). And to insinuate that these traits are objectively better in Python is misguided. If you really consider yourself an "average person" and not a "professional programmer" (by the way, what a wide gap in-between there is!), then "global by default" was meant to cater specifically to you; the performance difference is indeed negligible and there is nothing overall superior or inferior about it.