5 ms·
Lua is so nice, but I don't really use it for anything practical. I'd like to think that I'd rather have Lua as a language, with Python's class definitions and
by kzrdude 5y ago
Lua is so nice, but I don't really use it for anything practical.
I'd like to think that I'd rather have Lua as a language, with Python's class definitions and Python's ecosystem. What I mean by Lua as a language is the interpreter - and luajit - but also its `local` variables and scoping rules (Python's rules are rather strange, which the nonlocal keyword signals clearly).
- nerdponx 5y agoThe main downsides of Lua are the overloaded handling of nil, and the lack of a real standard library. If it weren't for that, it'd be a pretty nice general-purpose scripting language, arguably better than Python. I probably disagree with 90% of the criticisms leveled against Python, but it definitely is slow in "loopy" tasks, and the indentation-based syntax can make for relatively verbose code in quick ad-hoc scripts. I'd be plenty happy using Lua instead, if only it had a more thorough standard library. The nil-handling thing is annoying, but fine enough for quick scripts.
- pansa2 5y ago> the indentation-based syntax can make for relatively verbose code in quick ad-hoc scripts. Isn't significant indentation less verbose than Lua's use of `do ... end`?
- scythe 5y agoNot if you write one-liners like if x < 3 then x = 3 end I actually really like Lua's syntax, though I think a form for short Python-style lambdas would really help (short lambdas are the easiest ones to understand, so I don't see a comprehensibility objection, and Lua's grammar already makes the necessary expression-statement distinction). The Lua ecosystem was seriously damaged by the 5.1>5.2 split for a while since LuaJIT (hence Torch/nginx) and LÖVE both basically stayed with 5.1 and those were major projects that drew people to the language. The other cool unique thing in the Lua ecosystem, the native-widget (Windows/Gtk) IUP toolkit, remains barely known about and never ported to OS X, possibly due to a lack of Mac users in Brazil. Hence the "language without an ecosystem": it didn't happen for no reason, though the willingness to make breaking changes is a reason the language became so popular in the first place. NB. IUP is still around, but it still doesn't have a Cocoa port.
- nerdponx 5y agoMaybe a silly question, but isn't it possible to run Gtk applications on a Mac?
- pansa2 5y ago`if x < 3: x = 3` is valid Python, although I see your point - you could add an `else` to the Lua example but Python would require a second line. > a form for short Python-style lambdas would really help Interesting - many in the Python community feel that its lambdas (particularly the use of `lambda` as a keyword) are too verbose and would prefer something like `x => x+1`. Maybe such an arrow-function syntax is achievable with Python's new PEG parser - I'm fairly sure it couldn't have been supported by the old LL(1) parser.
- kzrdude 5y agoIn this particular example, Python has the more wordy `x = 3 if x < 3 else x` which you'd rather write as `x = max(x, 3)` to demonstrate Python's muscles in terms of useful builtins. About lambda syntax, to me it would be far more important to allow multiline lambdas than to have a shorter keyword.
- pansa2 5y ago> `x = max(x, 3)` to demonstrate Python's muscles in terms of useful builtins Even Lua has a built-in `math.max` function that works with integers. Maybe it’s Lua’s way of flexing on Go :) > About lambda syntax, to me it would be far more important to allow multiline lambdas than to have a shorter keyword. Never going to happen, unfortunately. It’s just not possible within the fundamental rules of Python’s grammar: that statements use significant indentation and expressions do not.
- deleted 5y ago[deleted]
- scythe 5y agoAll good points. Just compare: (lambda x: x + 1) (function (x) return x + 1 end) For arrow syntax I like this: ((x) -> x + 1) but reducing the number of keyword characters from 17 to 6 is already a big win.
- pkolaczk 5y agoNot a Lua developer here, what is the problem with nil? Just curious.
- wruza 5y agoNil serves as non-existence, so cannot be used as a normal value. You can’t have a table (an object/struct in other languages) that has “existing” nil-valued key, so it breaks json schemas. You can’t have an array that contains nil, because arrays are defined to be continuous tables if consecutive indices that do not have nil. #-operator may return either 3 or 1 for {1, nil, 1} array. You delete keys and last array values by setting to nil. People tried to introduce special NIL values (an globally-available table with clear testable indication of its purpose), but it never becomes a standard and as a result every lib that requires it uses it’s own.
- pull_my_finger 5y agoCouldn't you just use `false`? I was pretty opposed to the talk of adding an "undefined" value in the discussion prior to 5.4. As someone who has to write javascript fairly often having a large number of falsey values is definitely not something to be desired. I think in older versions of Lua there was a pattern to include an `n` field in your tables to keep track of it's length. Lua is all about "mechanisms over policy" and provides many ways to create tables that behave like arrays in Lua.
- cyber_kinetist 5y agoYou're right, Javascript's undefined creates a whole new set of problems that you don't want to deal with, at least Lua didn't make that mistake. But using False for invalid key accesses seems to be a really bad idea. Sometimes you need to store boolean values in tables. When that table access returns False then you don't have a way to tell if it was from a successful key retrieval or not. (Lua solves this dillema by making that storing nil in a table is just as if nothing really happened, which is pretty reasonable) If Lua had a more fleshed-out exception system (The current one based on pcall() is a bit limited both in syntax and functionality), I think it would have been better to go for the Python route (throw exceptions for invalid table access). Don't know how it will take a toll on performance though, maybe that's the reason why it chose such a simplistic route for implementing tables?
- 1vuio0pswjnm7 5y ago"Lua is so nice, but ..." Questions for the Lua critics. How many Python modules, e.g., in C, have you written. Which language is easier to write modules for, Lua or Python. Ever compare the startup time of the Lua interpreter to the Python one. What s the tally of applications that have embedded Lua interpreters versus those that have embdedded Python ones. Because it is (optionally) embedded in applications I use every day and/or rely on, whether it's a DNS load balancer, a TCP/HTTP proxy server or a fast OS kernel, I always use Lua for "practical purposes". Python seems to have development team of millions, but would I rather have a smaller interpreter with faster startup that is easier to write modules for. To me, that is an important question. Will I ever write Python modules in C for own use, or will I have to choose someone else's library and become 100% reliant on it. Does that limit the true "DIY" potential of Python vis-a-vis Lua. At least the parent did not use the "indices start at one" justification for concluding Lua is inferior. In the early days of Lua, that was a red flag to me that this language must be good, if that s the best criticism anyone could come up with.
- wruza 5y agoI was using Lua in the same ways for years, but after all that came to undeniable conclusion: you spend too much time writing static int l_foo(lua_State *L) { size_t len; const char *s = luaL_checkstring(L, 1, &len); luaL_newuserdata(…); return 1; } luaL_register(…); much more than appropriate. It feels like you are serving Lua, not the other way round. Reimplementing basic functions that Lua doesn’t have, writing too much glue in C to make it look like native interface. It is also very un-crossplatform when you use rocks (Lua’s PM). Lua is nice and fast and powerful with its metatables, environments and true coroutines, and I miss that in other scripting toy-languages like python and js. And if Lua took place in js ecosystem, we’d be much less fucked on the frontend side, exactly because of these mechanisms. But it is an engine without a cabin and wheels and nothing changes. As of nil, “:/.” and others like local…in, table=array, it just becomes an always-itching scratch after years. Lua doesn’t even respect full backwards compatibility (not that it was claimed) but its authors stick to the principles that many folks tried to un-convince them to no avail. language must be good, if that s the best criticism anyone could come up with That’s only the shallow surface, the real talk always goes in the mailing list before the release.