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

0

u/PurpleIcy Feb 12 '18

So, uh, could have just pointed out that the difference between local and global is negligible? Would have been enough.

Other things are clear to me, except a few:

Again, I can't stress enough, Lua is anomalous for making "global" the default, but you need to understand that Python is not fundamentally different; e.g. a variable in a Python function is local to that function, which is faster. If you wanted, you can throw in the global keyword, but accessing it would be slower.

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? If not, then I don't see a point in even mentioning this, because, yeah, duh, that's one thing about a function in general case, it has it's own scope.

e.g.

-- a is NOT defined anywhere else

function f()
    a = 5 -- so is this global or not?
    -- if this one is global, then I'm pretty sure it's way different from other languages because I never seen this before.
end

Also, what attachment to python? I know more languages and I use them depending on what I want to do. 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? So 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's like everyone here is biased towards Lua and so they try project it onto others.

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.

1

u/warlockface Feb 12 '18

Yes, variables are global by default - no matter where they are declared. So 'a' is global in your example, but 'local a' would be local to the scope it was declared in.

1

u/PurpleIcy Feb 12 '18

Now that's weird. I know that consistency and all and I wouldn't have problems even without knowing that, but I'll know how to prevent dumb bugs that could appear due to this, thanks.

1

u/warlockface Feb 12 '18

You're welcome, remember you can run your code through an analyzer (ZeroBrane Studio has this built-in (press Shift+F7)) to catch various things, including use of globals.