43 ms·
This is an unpopular opinion, but I wish Lua had won against python. It integrates seamlessly with C and for an interpreted language it’s super efficient. Rathe
by seibelj 9y ago
This is an unpopular opinion, but I wish Lua had won against python. It integrates seamlessly with C and for an interpreted language it’s super efficient. Rather than including every library under the sun in the standard lib, Lua is compact and the entire compiled binary is measured in kilobytes. You can read the Lua source code in C and comprehend a lot of it in a weekend.
Lua Rocks package manager includes basically every library you could want. Lua doesn’t even include proper object oriented programming, but is so powerful you can add support for it quite easily, and is a good learning experience for aspiring Lua programmers.
Lua is a great language, I wish it was mentioned and compared against more popular languages like Python and JavaScript.
- kirubakaran 9y agoDo you have any insights on why Lua didn't win?
- suby 9y agoI'm not OP, but I couldn't get past the fact that arrays start at 1 rather than 0.
- seibelj 9y agoTotally agree with you. Zero-indexed arrays are one of those language design dogmas that are simply set in stone, really awkward to switch between languages when Lua has such a fundamental difference of opinion.
- grzm 9y agoWhile many languages follow a 0-indexed convention, as you see here, not all do. Another couple of cases I run into are Postgres arrays, and switching between “first”, “second”, and “nth” in Clojure. If it helps, you can think 0-indexed as referring to the offset, and 1-indexed as referring to the position. It’s a shame to dismiss the entire language due to what one might argue is a minor aspect.
- runevault 9y agoClojure being a lisp also has different enough syntax it is easier to jump back and forth because you're doing way more context switching. Lua looks enough like other c-style languages you can forget it is 1 based and make all sorts of nasty mistakes. You can certainly argue it is unfair, but it is still something that increases the risk of mistakes.
- setzer22 9y agoReplacing (first coll) by (nth 1 coll) in clojure happens to me more often than I'd like to admit
- synthc 9y agoI would not call Clojure 1-indexed though because of 'first', it uses 0-indexing for list, vectors, and arrays.
- grzm 9y agoTo be clear, I’m not calling Clojure 1-indexed: I provided “nth” and “first” as examples of contrasting 0- and 1-based conventions; in this case within the same language.
- anta40 9y agoI mostly write in Java for work. Back to the good old high school days, I spent 2 years learning programming in Pascal (yes, Turbo Pascal for DOS!), so seeing arrays started at 1 is not something strange for me :) Of course, in Pascal you actually can pick any number where the index starts/end.
- rogual 9y agoFor me it was the fact that the array ends at the first 'nil' you store in it. 1-based arrays I could get used to; that was just maddening.
- accatyyc 9y agoSince Lua “arrays” are just tables with numerical keys, couldn’t you just start at 0 if that’s your preference?
- snarfy 9y agoThey don't have to, since Lua tables are hash sets and you can use anything as a key. You can start them at 0 if you want. table[0] = "foo" is valid and works. The downside is you have to add '-1' in a few places, but it's not as many as you'd think. All of my Lua code uses zero based arrays. I think the only place I had to add -1 was initializing numeric for loops.
- seibelj 9y agoI think the very reason I like it is the reason it didn’t crossover to mainstream success - it is so minimal it couldn’t compete with the all encompassing standard python library. NodeJS is an obvious counterpoint to my thesis - it’s minimal stdlib as augmented with tens of thousands of NPM packages to implement every feature. This is my preference, but maybe Lua was too early for this strategy to succeed. The vicious attacks NodeJS gets (read about the leftpad.js debacle) because of their philosophy shows that a lot of people disagree with me, but I like the small language augmented with a rich third-party ecosystem.
- setr 9y agoWhat I had drawn from the leftpad event in regards to ecosystem was the improper usage of third-party libraries; depending too much on libraries without actually validating what work they were doing, and how well they were doing it, and the realization this was common behavior throughout the community I don't recall anything particular to comment on small vs big std library. The above complaint would apply to either case
- nicklaf 9y agoPython and NodeJS both beat Lua because they were scripting languages involved with web servers and web clients, and the massive influence of the web on the job market meant that everybody was going to want to learn Python (and Javascript) and then try to apply it blindly to everything. It doesn't matter if either language might not be competitive with Lua or any other language in terms of design / features.
- bigtunacan 9y agoI would agree with this point in respect to Python, but not Node. I think Node was in large successful because web developers already have to use JavaScript so the promise of unifying on one language and set of libraries is appealing to many. OpenResty and Lapis are quite capable in the web space, but they haven’t seen widespread adoption.
- haberman 9y agoOne big reason is language stability. Lua changes the language in backward-incompatible ways. It’s part of how they make the language so clean, but it makes it difficult to build an ecosystem around.
- bigtunacan 9y agoThe lack of a large standard library and a decent package manager were key in my mind. I really love the simple elegance of Lua, but the build everything yourself ecosystem made Python and Ruby naturally better choices for larger non embedded solutions. These days the package management problem has been solved with LuaRocks, but many packages are unmaintained. The language is so old that it’s place seems to be set and unlikely to change.
- drallison 9y agoPerhaps there was not a race. Lua is a great language; Python is a great language. Both have a place in my tookkit. If you are into language design, Lua is a language worth studying and understanding.
- Pica_soO 9y agoIt didnt say- oh, btw you can use js functions and packages as library in lua. https://github.com/PaulBernier/castl https://github.com/PaulBernier/castl
- gilbetron 9y agoLong ago (in a company far away!) I evaluated Lua vs Python for use in a simulation engine as a scripting language for extending behaviors of stuff. Lua won, because of the easy integration with C and it's general lightness. However, I prefer Python. The big reason I like Python is that it doesn't try too much to be elegant, and happily creates specific functions for specific usages. I was able to get more done, more quickly in Python, even though I, from an aesthetic standpoint, though Lua was ... neater. I've since used Lua on numerous occasions, and I still love it. But I always reach to Python because of it's pure, raw usability.
- wvenable 9y agoWas Lua ever in competition with Python? Lua was for embedded systems and integrated as a scripting platform for other products. That's a vastly different market and design purpose than a general-purpose scripting language like Python. What has Python actual won over Lua that any other language hasn't won? I'm actually surprised JavaScript hasn't surpassed Lua for the kind of things Lua is designed for -- but Lua seems to hold on and people aren't generally embedding JavaScript as the scripting language for other programs.
- solarkraft 9y agoMongoose OS (iot OS) [0] uses embedded Javascript. [0]: https://mongoose-os.com/docs/quickstart/using-javascript.html https://mongoose-os.com/docs/quickstart/using-javascript.htm...
- _sdegutis 9y agoI started using JavaScript in my latest window manager after first using Lua. Since it’s for macOS the JavaScriptCore framework was already built in and uses the latest syntax. Honestly I prefer JS now even for embedding as long as it’s on macOS. Dunno how easy it is to embed on other systems.
- sifoo 9y agoWhy? There's nothing wrong with simplicity, cutting concepts down to their core and integrating well with C; quite the opposite. If you don't mind your Lua backwards and somewhat immature, Cixl is aiming in the same direction: https://github.com/basic-gongfu/cixl https://github.com/basic-gongfu/cixl
- rtpg 9y agoI think Python's standard library is super underestimated. I needed to work on zip files the other day and the Python standard lib included a great implementation with high quality documentation. Languages with minimal stdlibs tend to fall flat on the documentation front, and it adds a lot of friction imo. Though lua being embeddable is very nice, just coming from trying to embed Python and having a bit of frustration at managing it.
- jtolmar 9y agoI think we could use a reasonable middleground between the awesome standard libraries of Python and Java and the ocean of tiny packages of Rust and Javascript. It'd be nice if a package-managed language could import the huge awesome standard library, automatically drop whatever goes unused, and that mechanism worked well enough that everyone but the most restricted embedded programmers were fine with it.
- rtpg 9y agoTotally. I think that if you can build your dependency graph properly you don't need to package the standard library. The standard library exists partly because packaging was hard, so it's easier to ship a bunch of stuff. But nowadays it could simply be "core libs" that get pulled in on use.
- pjmlp 9y agoPackaging is only part of the whole equation. Quality, available documentation, guaratee of supporting every OS targeted by the language toolchain, and future updates in sync with the language version also matter.
- jasonkostempski 9y agoGoogle Closure does a pretty good job at stripping unused code. ClojureScript is powered by Google Closure. Leiningen gets you package management.
- MikkoFinell 9y agoInstead of Lua, I'd like Scheme to have become a more popular language for all those reasons you mention.
- egnehots 9y agoIs there any flavor of lisp that is close to luajit performances and still small?
- deleted 9y ago[deleted]
- shakna 9y agoGambit-C [0]. It's a R5RS Scheme, and is near-C level of performance. It compiles to C, so embedding it is fairly easy too. Compiles to static executables, which is easy for distribution. Chez Scheme [1]. It's a R6RS Scheme, so bigger, but Chez has much better embedding support, is backed by Cisco instead of a single dev. Chez doesn't make standalone executables though, because Chez is jitted. It may be the fastest Scheme. It also includes a compiler, a profiler, a great debugger, live memory-introspection, and an enhanced REPL [2] that can dump out it's definitions and any comments into a lovely Scheme file. [0] https://github.com/gambit/gambit https://github.com/gambit/gambit [1] https://github.com/cisco/ChezScheme https://github.com/cisco/ChezScheme [2] https://cisco.github.io/ChezScheme/csug9.5/use.html#./use:h2 https://cisco.github.io/ChezScheme/csug9.5/use.html#./use:h2
- bjoli 9y agoChez is not JITted. Chez compiles to native binaries that run win the chez runtime (so not stand-alone).
- shakna 9y ago> Source code is compiled on-the-fly when loaded from a source file or entered via the shell.[0] > Whether compiling on the fly or precompiling, the compiler produces optimized machine code, with some optimization across separately compiled library boundaries. [0] > Chez Scheme compiles source forms as it sees them to machine code before evaluating them, i.e., "just in time." [1] Chez can both JIT and pre-compile. But it absolutely has a JIT, and has had as far back as I could trace. [0] https://cisco.github.io/ChezScheme/ https://cisco.github.io/ChezScheme/ [1] https://www.scheme.com/csug8/use.html https://www.scheme.com/csug8/use.html
- Sevrene 9y agoI've seen far more game engines implement Lua as their scripting language compared to python, so I would hardly say it's 'lost' against python, at least for video games.
- pjmlp 9y agoVideo games is where Lua started to gain attention in first place.
- Matheus28 9y agoLua is a great language Debatable: 1. Arrays start at 1 2. "begin" & "end" instead of {} 3. No ++, +=, etc. 4. No bitwise operators 5. No "continue" statement 6. Uses "~=" instead of "!=" Those are just the ones I remembered off the top of my head. It goes against so many modern conventions that makes it a pain in the butt to work with.
- snarfy 9y ago1. array[0] is syntactic sugar for *(array+0). 0 is an offset from an address, not an index. Lua has tables. Tables have indexes. Indexes start at 1. 2. a design goal was to be easy for new users, not just existing programmers. begin/end was borrowed from SQL. 3. Less operators is less to learn. New users are familiar with +, -, *, /. Operators like ++, --, *=, increase the learning curve. x = x + 1 is not hard to grasp. 4. No bitwise operators because no integers. numbers are floats. 5. continue statement is not necessary, adds more complexity. 6. Why should it be '!=' and not '<>' I'm not sure it goes against modern conventions, but it does go against a few C conventions. Not all languages need to be C like.
- groovy2shoes 9y ago1. Tables in Lua have keys. Any value other than `nil` may be used as a key, including `0` if you so desire. 2. Lua's usage of `begin`/`end` was borrowed from "Modula" according to the HOPL paper[1]. Probably Modula-2, but the timeframe would not exclude Modula-3 as a possibility, though I suppose it doesn't really matter. 3. I find this to be a poor argument, but I've never felt like I was missing out on a whole lot by not having modification operators in Lua, either. It's not something that comes up often enough that the couple extra keystrokes should be a deal-breaker. 4. Lua added integers alongside flonums in 5.3, along with bitwise operators, but it's been possible to configure Lua's number representation at compile time for as long as I can remember. Prior to 5.3, anyone with a usecase that really necessitated bitwise operations could easily add them with a dozen lines of C code, or they could use LuaJIT which has offered bitops for some time. I agree completely with points 5 and 6; nothing to add there :) [1]: https://www.lua.org/doc/hopl.pdf https://www.lua.org/doc/hopl.pdf
- adwn 9y ago> I wish Lua had won against python Thank goodness it didn't. The number one benefit you should get from a scripting language as opposed to a compiled one is higher productivity – otherwise, you could just write it in C and have higher performance and lower resource usage. What good is a scripting language where I have to either implement every utility function myself, or look for and include an external library? Lua does not even have a round() function! [1] You can't just write print(some_table) [2], which makes using the REPL needlessly burdensome. Sure, as an embedded scripting language in very small, resource-constrained devices this is a good strategy, but that's a niche application. Even worse is the "arrays are hashtables in disguise" concept, because even though it might appear to be elegant, it doesn't work well in practice. In the end, you have to treat arrays and hashtables differently (see, e.g., pairs() and ipairs()), because – big surprise – arrays and hashtables are very different conceptually, so you don't gain much from unifying them. Also great is that if you set element #5 in a 10-element array to nil (maybe you write foo[5] = arg1, and arg1 comes from a caller), your array suddenly only has 4 elements. That's because the first nil in a hashtable demarks the end of an array. Similarly, you might get an array argument from a caller, check its length (4 elements), append a single value, and suddenly your array has 10 elements, instead of 5! That's terrible design. [1] But it does have functions to convert degrees to radians and back. How is that more important than round()?! [2] Lua will just print the address of the hashtable, which is completely useless if you want to see its contents.
- jgtrosh 9y agoThe lua interpretors are just fine ; it's not because it's designed to be easily embeddable that it doesn't work just fine on its own.
- adwn 9y ago> The lua interpretors are just fine I don't think I complained about the Lua interpreter itself? > it's not because it's designed to be easily embeddable that it doesn't work just fine on its own. I don't understand that sentence.
- 9y ago
- eftychis 9y agoLua and python don't really compare in my mind. Lua is much more of a glue language, i.e. extending the application via the C API. It is designed around extending application -- and itself. My knowledge of Lua is limited, however, so could you elaborate on the comparison criteria? I mean I wouldn't personally compare Python and Javascript. To be honest I wouldn't compare Javascript with anything. Python's design is around readability. It is interpreted, while Lua runs via a VM. I guess they are both extensible, although I don't have Lua experience in this area to compare. Would you care to add a bit more information?