News for hackers. Stuff that matters.

Lua Criticism Is Unwarranted

1 based syntax - it is easy to define functions that are index-agnostic or correct off by 1 errors. Looks like people don't want to define a single trivial function. I like how erlang handles indices - by not really relying on them much

2. nil-handling - no dynamic language has good nil handling. The proper solution is having optional types. People cannot grasp the fact that nils in control flow do not have to be equivalently implemented in data structures. Having nil and false is the same thing when nil is treated as a value than an empty variable which causes confusion because nil is supposed to denote absence. This leads to all such langs having 2 functions for retrieving and checking key's existence. Because treats nil as literal absence of value whilst allowing nil variable declarations is not illogical because since you have declared it, you might use it in the future. Because lua requires explicit declaration of local variables, it does not make sense to ignore a nil-defined variable to be omitted from the syntax but because nil is absence, it does not make sense to treat it as a presence in a mapping structure because mappings are treated as literally dynamic which makes nil a key deleter and a sign of nonexistence. This should not have a bearing on development because false still signifies an extant binding while nil does not

3. Unified containers aka tables If people jerk off to polymorphism, a united container should not hurt because almost all languages have identical indexing syntax for all containers. Similarly all dynamic languages require type checking to distinguish among values and it is easy to write an is_list and is_dict structure

4. Iteration sucks - the iterators are ridiculously very powerful because there is no generator syntax nor any special keywords. It is just a closure. Lua closures are perfectly made and callback based programming is extremely consistent and often idiomatic in lua

5. Local declaration I think it is similar to var declaration in statically typed languages. This has something to do with lua not using tables like python and instead using registers. Global declarations are the programmer's fault because the lua guide clearly states that the global table is a 'table'. So the nil logic applies here.

6. Is too simplistic People mistake terseness with simple here. By simple they usually mean the lack of syntactic sugars which makes many not-so-intuitive things seem much harder in lua. For example list slices in langs with slicing syntax involve a generator across an index range which retains the memory location to allow list manipulation via slices. That is certainly not easy for most noobs who just want a table slice. Now i agree that the stdlib sucks with regards to table ops, there are plenty of good libraries out there

6. No type system Then you have probably taken types as a concept too far to the point of mere visual and heuristic convenience. Types can be largely be understood via set theory which is middle school math. It is a shame then how cs kids and working professionals i have met being unable to grasp anything that does not have the default syntactic sugars of their working languages. Is it so difficult to create an object by just setting some attribs and tagging the table with a name? If you have grasped set theory then you can almost certainly create your own valid type system with ease.

KeyErr

I consider lua to not be an easy language to learn despite it itself advertises as being an easy language to learn. I think it has a simple design but is not simple to learn much like mechanical engineering which goes beyond jamming nuts, bolts, screws to wood and creating simple pulleys for your wells but when a mechanical engineer grad cannot construct a double pulley for their grandpa's well then you know what it means

( 27 comments | 9 points | on HN )
Re:Lua Criticism Is Unwarranted by dtagames on Thursday October 26, 2023 @09:33AM (#38025279)
Lua came first but was both encouraged by and hampered by Brazil's limitations on technology imports at the time. The lack of access to other tools is what led the team to develop it in the first place. But the country's lack of connection with other IT outlets at the time prevented Lua from taking over.

If Lua had gotten "out in the wild" earlier, it would be where JS/TS are today. It's just as powerful as JS and more in some ways, such as embedding and encapsulation. It's also widely used as a modding language in the game industry precisely because it can be "dropped into" another project and allow coding in a limited way without affecting the other project.

Re:Lua Criticism Is Unwarranted by Joker_vD on Thursday October 26, 2023 @09:40AM (#38025367)
> Is it so difficult to create an object by just setting some attribs and tagging the table with a name?

Is it so difficult to create a struct by just memcpy-ing some data into a malloc-ed buffer and not even putting a tag anywhere? No, it is not. Neither is reading the fields back by using the pre-computed offsets. But people for some reason dislike writing such easy code by hand.

Re:Lua Criticism Is Unwarranted by caligian on Thursday October 26, 2023 @09:37PM (#38033723)
Using a table is still simpler because people literally use dicts everywhere without actually thinking of them as containers but only as 'lookup containers'
Re:Lua Criticism Is Unwarranted by yakubin on Thursday October 26, 2023 @09:39AM (#38025360)
Lua is pretty much the standard extension language for tools like nmap, wireshark, DarkTable, Hammerspoon, …

I think it’s doing pretty well and am happy with this fact. I think its success is well justified.

So I’m not sure about it being overly-criticised.

Re:Lua Criticism Is Unwarranted by sneed_chucker on Thursday October 26, 2023 @09:35AM (#38025300)
Not sure there's all that much Lua criticism around here?
Re:Lua Criticism Is Unwarranted by cies on Thursday October 26, 2023 @09:38AM (#38025344)
Read my comment :)
Re:Lua Criticism Is Unwarranted by caligian on Thursday October 26, 2023 @09:46PM (#38033758)
It is constantly called one of the worst programming languages. Coders i know want to touch lua with a 10-feet pole.
Re:Lua Criticism Is Unwarranted by krapp on Thursday October 26, 2023 @10:11PM (#38033905)
Any language you can pick is considered one of the worst programming languages by at least a small pitchfork-wielding mob of programmers. Like Bjarne Stroustrup said, there are two kinds of languages - the ones people complain about, and the ones no one uses.

Getting worked up about defending the honor of programming languages is a waste of time. People either have technical reasons to choose one language over another within a specific use case, which is valid, or else their opinions are based on aesthetics or memes, which you can't really argue against effectively. Just accept that sometimes people won't like the things you like, for reasons you can't accept.

Also if you want to use arrays and structs in Lua, and you're fine being stuck with 5.1, you can always just use LuaJIT and have actual C structs and arrays. Best of both worlds, in my opinion.

Re:Lua Criticism Is Unwarranted by caligian on Saturday October 28, 2023 @09:46AM (#38049753)
Far from defending the lang's honour. There are many noteworthy things about lua. Firstly it encourages you to use query-able data structures. Lack of first class objects makes marshalling extremely easy. This is similar to using elixir which only as dicts, lists, tuples and structs. Arguably elixir is even simpler than lua when it comes to describing data because of lack of ANY OOP features that makes the object opaque with getters and setters
Re:Lua Criticism Is Unwarranted by cies on Thursday October 26, 2023 @09:37AM (#38025329)
I've built something with Lua because the lovely Love2D game lib prescribed it. I hated almost everything about it (globals, stdlib, silly typing discipline, debugging, syntax). Rewrote the whole thing (when it was small) to Kotlin and libKDX (a wrapper over libGDX). Experience was so much better it's not even funny.

Lua felt like JS and PHP had a secret child they abandoned and somehow survived up growing up in a dumpster.

I know I should not bash open source software: I know it takes a lot of work to build/maintain it. I'm merely reacting to this post.

Re:Lua Criticism Is Unwarranted by jacknews on Thursday October 26, 2023 @10:08AM (#38025789)
tbh they seem like two completely different worlds, and if you're experienced in the java ecosystem (or have a C/C++ mentality), then this makes perfects sense.

But I'm not sure java is exactly without criticism either.

Lua and Love2D (and with Fennel on top) makes for a good teaching setup, IMHO.

Re:Lua Criticism Is Unwarranted by caligian on Thursday October 26, 2023 @09:43PM (#38033748)
While attempting to teach callbacks to a room full of C# devs i figured lua was the easiest for creating readable examples. The language has very good teachable aspects. I'd pick lua over python as a teacher to teach data structures
Re:Lua Criticism Is Unwarranted by cies on Thursday November 02, 2023 @12:42PM (#38116262)
I'm experienced across many languages. Including Haskell (professionally), Rust (for fun) and Ruby/Python/TypeScript.

When you say "fennel on top", sure that makes all the difference! I've argued in favour of using a LISP/Scheme for teaching students in the local uni i'm active in, but the businesses requesting "give us close to Java/C# certified graduates" won.

Edsgar Dijkstra wrote a nice piece on this.

https://www.cs.utexas.edu/users/EWD/transcriptions/OtherDocs...

Re:Lua Criticism Is Unwarranted by caligian on Thursday October 26, 2023 @09:41PM (#38033743)
I agree with your criticism. I could not properly use lua without creating my own set of table utils and structs (they are faster than classes)
Re:Lua Criticism Is Unwarranted by badrabbit on Thursday October 26, 2023 @09:37AM (#38025341)
I have no problem with Lua but you forgot to address how it starts counting array indexes at 1 not 0, or is that what your first point is addressing ?
Re:Lua Criticism Is Unwarranted by caligian on Thursday October 26, 2023 @09:39PM (#38033733)
Yes. My point is that it should not matter because you can stick to table indexing with +-1 or create a function for the same
Re:Lua Criticism Is Unwarranted by Joker_vD on Friday October 27, 2023 @02:28AM (#38035318)
So what does this "simple function" look like?
Re:Lua Criticism Is Unwarranted by caligian on Friday October 27, 2023 @04:02AM (#38035888)
function mod0(x, y) return (x % y) + 1 end

Something like this? You replace % with mod0()

Re:Lua Criticism Is Unwarranted by juancn on Thursday October 26, 2023 @01:27PM (#38028833)
LUA for me has a vintage feel to it. Like REXX or TCL.

I find it a bit difficult to write, but that's probably lack of experience with it.

I normally use it for customizing something that forces me into using it, so I don't really want to spend the time knowing its intricacies, so anything where it diverges from more popular languages it grinds me and I try to avoid.

But this is true of any language that feels unfamiliar.

Anyway, Language adoption is a bit of luck and a bit of personal taste. A language needs a certain critical mass to become popular.

Re:Lua Criticism Is Unwarranted by srhtftw on Thursday October 26, 2023 @03:43PM (#38030778)
I had the pleasure of working with Lua 5.1 back in the late noughties. For me it replaced Tcl whenever I wanted something I could configure above a C library. At the time I used it I found it quite nice but I'll also not forget the hours I wasted tracking down nil table corruptions which could have easily been caught by a type checker.

I had some hope that Luau https://luau-lang.org or Teal https://github.com/teal-language/tl would make things better but with the following example

    function foo(x: number): string 
      if x == 2 then return nil else return "foo" end
    end
    
    x = { foo(1), foo(2), foo(3) }
    
    for i,v in ipairs(x) do
     print(i,v)
    end
they produce no warning and sadly only print

    1 foo
When I was younger I might have put up with that sort of WTF but now that I have better options I try to stick to type checked languages where I don't have to.
Re:Lua Criticism Is Unwarranted by caligian on Thursday October 26, 2023 @09:36PM (#38033716)
This is one of the things i was talking about. You cannot map nil to a key because nil means absence. The compiler can only infer such absence at a control flow level aka passing arguments to functions or checking nil-variables. You are supposed to use false in such a case here
Re:Lua Criticism Is Unwarranted by srhtftw on Thursday October 26, 2023 @10:46PM (#38034116)
To me this is a serious flaw and I simply refuse to accept that it's beyond criticism. No language should allow its collections to be corrupted this easily. Especially when a key use of the language is configuring other software.

Fortunately there are other configuration languages available now besides Lua which provide type checking, so I remain hopeful that a future version of Lua or one of the newer typed Lua variants will eventually learn from those.

Re:Lua Criticism Is Unwarranted by caligian on Saturday November 04, 2023 @11:15PM (#38147728)
There is no 'corruption' happening anywhere.

When you register local variables, they are merely defined as register locations and have a default value of nil which is absence and hence memory saved. They would have to mark nil explicity as a new data structure which is probably wastage as they would have to allocate memory for every variable declaration that may or may not be used.

It is just nil, nil at a literal level with the exception being local variables which are handled differently as offsets to register locations than other dynamic languages without such 'local' qualifiers.

Re:Lua Criticism Is Unwarranted by cxr on Monday November 06, 2023 @01:47PM (#38166909)
> I found it quite nice but I'll also not forget the hours I wasted tracking down nil table corruptions which could have easily been caught by a type checker.

> I had some hope that Luau https://luau-lang.org or Teal https://github.com/teal-language/tl would make things better

Inline type annotations are not a prerequisite for typechecking; there's nothing stopping you from writing straight Lua (or whatever) and then having a separate tool that does typechecking _without_ having to change the language. People are failing to take away the most important lessons from TypeScript.

The same goes, frankly, for languages that ostensibly have typechecking but have such deficient type systems that it's not exactly that much better than not having one. (Like C, for example.) Considering that type annotations are more valued for being a form of documentation than they are valued for making it easier to write the compiler's code generator...

If you have a function like printf that is ostensibly typechecked but not really, and you already have documentation (like man pages) for that function that says that the arguments need to be such-and-such, but the typechecker for your compiler/IDE isn't able to factor that in at or before build time, then that's a compiler/IDE problem, not anything that necessitates a change to the original grammar.

Re:Lua Criticism Is Unwarranted by caligian on Thursday October 26, 2023 @09:54PM (#38033802)
https://github.com/caligian/nvimconfig

https://github.com/caligian/lua-utils

The former uses the latter for nvim. And the latter makes lua perl with structs. We all loved perl for its lispy functions to deal with lists - grep, map, push, shift, unshift, etc. Nested ops are inspired by elixir.

Re:Lua Criticism Is Unwarranted by caligian on Thursday November 02, 2023 @01:00PM (#38116559)
Let's take another example. Consider structs as tagged tables with a metatable key that distinguishes it from ordinary tables. You can implement inheritance as chained __index closures for parent tables or simply chained tables. Or you can use the struct as is by defining a global table and creating a simple lookup. Theoretically the lookup will work faster because you can store the hierarchy as an list, run a simple index() to get the needed parent and call the method in the associated table. This is much faster than going to multiple chained tables thus slowing down lookup.

Another example is python iterators which requires a separate instance with __next__ method. It is not generic because now you can create n instances for n dicts just to use it in for syntax. Whereas in lua it is a simple closure returning the next value until nil

Re:Lua Criticism Is Unwarranted by rlawson on Friday November 03, 2023 @09:44AM (#38128661)
I very much like Lua and the fact that I can hold much of the language in my head. I do hate the local/global thing but on the other hand I really do appreciate it's simplicity