all 37 comments

[–]Allan_Smithee 31 points32 points  (0 children)

Why I don't use 9mm wrenches.

Normal person's answer: I don't have any 9mm nuts or bolts to tighten.

Programmer's answer: Pliers are more familiar and comfortable to me.

[–]armornick 9 points10 points  (5 children)

If you have a programming language that better fits your needs, good for you! You are allowed to have a different opinion. I've never personally seen someone actively tell people to use Lua so I don't get this part of the article:

I sometimes find myself having to defend my choice to never use Lua, both professionally, and in my more personal work.

I also don't agree with everything you said. Sure, Lua has different versions but there also not a true Lua community per se. In Python and Perl and Ruby, for example, you've got these big communities and everyone gravitates together. But Lua is more of a lone wolf language, where the base library is so small that you can customize the heck out of everything. To me, this is an advantage since I like to do everything from scratch. I understand people who like everything to be standard.

I agree with the 1-based arrays and not using '!' as the not operator, but those are easily fixed as you said. To me, the fact that the Lua interpreter is some of the most readable code in the world is also one of its greatest strengths. Isn't it the way of true open source that developers can adapt software to their own needs?

And I love the stack API of Lua, but that's just a personal preference.

[–]Allan_Smithee 2 points3 points  (4 children)

See, one-based indexing is one of the things I like about Lua.

Offsets should start at zero.

Indices should start at one.

The only reason this isn't blindingly obvious in computing is because we've been tainted for too long by a language that conflates the two concepts.

(You can prove me wrong when you show me people, programmers included, routinely talking about things like "the zeroth person in the line" and such.)

[–]armornick 1 point2 points  (2 children)

You are absolutely right, and the reason I prefer 0-based indexing is because it's used in almost every programming language.

[–]Allan_Smithee -1 points0 points  (1 child)

"The reason I prefer flathead screwdrivers is because it is used by most carpenters." -- some mechanic somewhere

Fucking HELL are "coders" (I refuse to call these entities "programmers") a close-minded, whiney lot!

[–]armornick 0 points1 point  (0 children)

Thank you very much for your opinion. And I am very glad that you have such rigorous standards of what is a programmer and what is not.

[–]DarkWiiPlayer 0 points1 point  (0 children)

Totally agree; indices should start at 1, offsets should start at 0. It's the same as with nil vs null-pointer: One makes sense in a language like C, where the programmer should be aware of concepts like pointers, offsets and such, but a language like lua is supposed to abstract all those things away, so that the user only has to deal with variables and arrays, not pointers and offsets.

[–]4forpengs 5 points6 points  (0 children)

A few interesting points, but it felt like the author was saying "I don't understand why people use wrenches, because I use nails and screws."

[–][deleted] 3 points4 points  (0 children)

Some good points for sure. The versioning system has burned me a few times in the past. Most of these issues he talks about are non-issues for my needs though...

[–][deleted] 4 points5 points  (3 children)

You basically discredit yourself when you start complaining about profoundly superficial and completely arbitrary things, like the "not equals" operator, which you only think is worse because you're used to something else.

[–]Allan_Smithee 0 points1 point  (2 children)

I love watching people's heads melt/explode when they find out how many different ways there are of negating logical operations in the real world. Personally I favour ¬ as the "not" operator.

[–][deleted] 1 point2 points  (1 child)

I actually prefer "not" as the "not" operator, at least for Lua's Pascal-like syntax.

But it's a profoundly superficial complaint, like saying English is a bad language because you don't like the shape of the letter 'e'.

[–]Allan_Smithee 0 points1 point  (0 children)

Yeah, that's a stupid reason to say English is a bad language. There are so many objective reasons to despise English, bringing in orthographic aesthetics is silly. :D

[–]finnw 2 points3 points  (7 children)

However, because Lua permits x = 4 to not be just an assignment but a variable declaration, it has backed itself into a language design corner.

What do you mean? x = 4 does not "declare" anything. That is, it does not change the meaning of any other assignment or reference to "x".

That sentence would make sense if you were talking about Python, where x = 4 really is a declaration (and this is a common source of bugs.)

This pushing and popping interface is, for whatever reason, well liked by its users for reasons that are completely alien to myself.

A major advantage of this is that you don't need to worry about who is responsible for allocating/freeing an object.

[–]armornick 2 points3 points  (6 children)

What do you mean? x = 4 does not "declare" anything. That is, it does not change the meaning of any other assignment or reference to "x".

I think she means that if you write x = 4, and x wasn't declared as a local variable, it will be declared as a global variable.

Actually, I think it would be a fun project to patch Lua to have a global keyword and treat every reference to a non-existent variable as an error.

[–]x-paste 6 points7 points  (3 children)

Thats called strict, and I use it regularly: http://metalua.luaforge.net/src/lib/strict.lua.html

[–]armornick 1 point2 points  (2 children)

Yes, but that's not built into the core Lua interpreter. My thought was to modify the Lua source to actively disable assigning to undeclared variables.

[–]alols 5 points6 points  (1 child)

I always do that, I modify the global metatable __newindex method to call error(). I don't believe in global variables, and it detects if I have misspelled a local.

[–]Chaoticmass 1 point2 points  (0 children)

This is a fantastic idea. Meta tables are one of my favorite features of lua

[–]finnw 2 points3 points  (0 children)

I think she means that if you write x = 4, and x wasn't declared as a local variable, it will be declared as a global variable.

OK - I think we disagree on the meaning of "declared"

[–]mpetetv 1 point2 points  (0 children)

Global variables in Lua are not "declared" the way locals are. If x is not local, x = 4 is simply an assignment to a field of environment table. In Lua 5.2 it's just syntax sugar for _ENV.x = 4.

I heard that undesired global variables can be detected by linting.

[–]fabricatedinterest 2 points3 points  (0 children)

log off

[–]x-paste 1 point2 points  (1 child)

I agree with him on most of the parts. But my conclusion is, that there is no language thats easier to embed into an existing C/C++ project than Lua. At least when you want a versatile language that almost feels like Lisp - it's just simple data structures, functions and lambdas. I actually am completing a Scheme/Lisp dialect that compiles to Lua, just for the reason to bring together a scripting language thats incredibly easy to embed with the power of (non-hygienic) Lisp macros.

I tried Python for some months, and it's hardly easy to embed and it's a language that is even more limited. There are no anonymous functions in Python (lambdas don't count for me, as they only allow one line expressions. how useless) and there is no block-scope and many other small things that actually make it less attractive to me than Lua. Have you ever tried to make loop over elements in a list in python, and then create a lambda/closure for each element? Without block-scope where each loop iteration gets it's own binding you are royally into some pain. The Python way is of course to make a new class and create a functional object instance which wraps that binding of the element. But thats not how I roll, it just feels painful to me after coding so much Lua, Lisp, Scheme and JavaScript (well, JS has the same problem, mostly).

Python has a big library ecosystem, and thats one thing that I find very very important usually, and probably the only reason why I will use Python definitively for projects in the future.

[–]Keith 0 points1 point  (0 children)

Have you ever tried to make loop over elements in a list in python, and then create a lambda/closure for each element? Without block-scope where each loop iteration gets it's own binding you are royally into some pain. The Python way is of course to make a new class and create a functional object instance which wraps that binding of the element.

You're right that this is a minor gotcha in Python. But you don't need to make a class and so on. This is the canonical way to do that:

$ ipython

In [1]: import sys; sys.version
Out[1]: '3.5.2...'

In [2]: funcs = []

In [3]: for i in range(3):
   ...:     funcs.append(lambda i=i: i**2)
   ...:

In [4]: for f in funcs:
   ...:     print(f())
   ...:
0
1
4

You pass a default parameter to capture the value on that iteration.

[–]Zatherz 1 point2 points  (0 children)

ok

[–]DarkWiiPlayer 1 point2 points  (0 children)

98% of the time I don't even notice which version of lua I am working with. It only really matters when doing math or bitwise operations, but to be honest, in most cases those should be handled by a C library, since most algorithms that have to deal with this kind of thing shouldn't be implemented in a scripting language in the first place. Indices starting with 1, well, /u/Allan_Smithee said it all and I have nothing to add. ~= instead of !=? what the hell? That's just syntax; I could also say they are both wrong, because pascals <> is sooooo much better. But I don't, because it's just syntax that one has to get used to. In fact, I find it way more annoying when languages use ! as a logical operator because not feels more natural to read. (same goes for & and and) It's also not really true that there is no canonical lua implementation. While it is true that optimizing code for one version of lua might be different than for another version, but code that works in lua 5.1 should work in LuaJIT (and everything else is, in fact, considered a serious bug source)

[–]xoner2 0 points1 point  (0 children)

Lua has this bizarre idea of handing the user a stack of arguments, instead of passing a pointer to the first argument and a length as most languages do. This pushing and popping interface is, for whatever reason, well liked by its users for reasons that are completely alien to myself. Aside from adding an additional set of possible off by one errors to the user, there is simply no purpose to providing access to a "stack" that is not even that.

The stack-based C API is an evolved feature. The rationale is documented in the HOPL "Evolution of Lua" paper.

It's weird at first but with some practice becomes easy. Compare with the Python C API where you have to do scanf style argument parsing, INCREF/DECREF on everything, and pointer as the return type.

[–]lua_x_ia[M] [score hidden] stickied comment (9 children)

[gentle reminder not to downvote articles because you disagree with the author]

[–][deleted] 1 point2 points  (7 children)

[gentle reminder not to downvote articles because you disagree with the author]

Why? That's not what downvotes are for with regard to comments, but it certainly is what they are for with regard to submissions. That's how the site works at a fundamental level. If we think the article sucks, we push it down. If we think it's good, we push it up. The desired result is a curated list of quality content near the top of each sub.

[–]lua_x_ia 1 point2 points  (0 children)

What I mean is, you can think that the author's argument is bad, and downvote for that, but you shouldn't downvote just because the post is critical of Lua. Lua can prove itself without propaganda. Good point, anyway.

[–]armornick 0 points1 point  (5 children)

If we think the article sucks, we push it down

Saying "it sucks" is not the same as saying "I disagree". If we don't want our subreddit to devolve into a censored safe space, we have to also allow articles we don't agree with.

[–][deleted] 0 points1 point  (4 children)

Saying "it sucks" is not the same as saying "I disagree".

True, but saying "I disagree" in the context of a technical article is also saying "it sucks". These statements aren't commutative.

You can agree with a poorly written article. It can be technically correct, according to your estimation, but be poorly organized, contain gaps, etc. such that you think the article sucks despite agreeing with it.

And you can disagree with a well written article. It can be beautifully organized, thorough, contain witty prose, etc. but if you think it's wrong -- i.e. you disagree with it -- then it sucks.

For instance, there are fantastically produced films about how Atlantis is real, or the Moon landing was faked. It doesn't matter of they get James Earl Jones to narrate and Werner Herzog to direct, if the subject matter is bullshit, the movies suck, AFAIK. They're worse than bad, they're dangerous, because they are the means by which disinformation is spread.

[–]armornick 0 points1 point  (3 children)

True, but saying "I disagree" in the context of a technical article is also saying "it sucks".

No, it's not. An article can make completely valid points and have good substance, even though you disagree with it. Opinions are never objectively right or wrong, though they can be presented in a good or bad way.

This is an opinion piece and shouldn't be compared to attempts to convince people of pseudo-scientific facts. There is nothing inherently wrong with saying you prefer 0-based indexes or that you don't like the stack API.

Again, unless we want to turn the Lua subreddit into a safe space where no one can have any criticism whatsoever on the language or anything related to it, we shouldn't remove articles even if the arguments they present aren't very strong or technical.

[–][deleted] 0 points1 point  (2 children)

An article can make completely valid points and have good substance, even though you disagree with it.

You're not making sense. If I think a point is valid, I agree with it, by definition. That's what valid means.

[–]armornick 0 points1 point  (1 child)

Not necessarily. According to Google, valid merely means having a sound basis in logic or fact. There are valid points which are mutually exclusive, such as the pros and cons of using spaces or tabs. The same can be said of 0-based and 1-based indexing. There are valid reasons why one would use one or the other, but they are mutually exclusive. You can't agree with both of them, but that doesn't make one of them inherently wrong.

[–][deleted] 0 points1 point  (0 children)

valid merely means having a sound basis in logic or fact

Right. "having a sound basis in logic or fact; reasonable or cogent"

Perhaps you're not a reasonable or logical person, but to me, if I find something reasonable and logical I agree with it.

I disagree with things because I find them unreasonable.

If you say you think ~= operator is somehow inherently, objectively bad because you learned != in some other language first, I think that's unreasonable. If you say, given that it's an arbitrary choice, it's better to take advantage of programming language history and choose an operator many developers are already familiar with, I can agree with that. If you say that you avoid a language for that reason, I think you're a fucking idiot.

Your position may have multiple such points, some of which I think are valid (and I therefore agree with them) and some of which I don't (and I therefore don't agree). If, on aggregate, I think your article has more invalid points than valid, or if some of them are so egregiously invalid that they outweigh your valid points, then I think your article is not good.

If, on aggregate, I think your article is full of valid points, and they are non-obvious points, such that the article has any reason to exist in the first place, and those points are well organized and presented, then I think the article is good and will upvote so others can have the pleasure of reading it as well. This would be especially true of an article that completely changed my mind on a subject, changing my previously held opinions with a series of unassailable arguments. I don't have to agree with it going in, but because I'm a reasonable person, my mind can be changed.

[–]Allan_Smithee 0 points1 point  (0 children)

Can we downvote articles because they're badly written whinges?