5 ms·
It has all the power of something like Python, but is much faster and with far less cruft and basically no confusing elements. You’re given a small set of tool
by friedturkey 5y ago
It has all the power of something like Python, but is much faster and with far less cruft and basically no confusing elements.
You’re given a small set of tools and it’s incredibly easy to build off them.
- chii 5y ago> basically no confusing elements. the one confusing element - one-based indexing of arrays! that is something i found hard to adjust, as it makes off-by-one errors more prominent... but otherwise it's a nice language.
- toastercat 5y agoThat's not really confusing though, just takes a bit of unlearning the muscle memory of 0-based indexing.
- donatj 5y agoI certainly prefer 0-indexed these days, but starting on 1-indexed languages (A variety of BASIC’s) I found 0-indexing just as weird.
- DonHopkins 5y agoI agree, that's the one unfortunate flaw of Lua I'd go back in time and change if I were Hitler With a Time Machine, but I've used Lua and other 1-based languages like ScriptX, and you totally get used to it, and finally realize that 0-based languages have their own confusing quirks and inconveniences that you got used to when you learned them, and you just don't think about them any more once you've internalized them, just like 1-based languages. It's just a matter of moving the confusing quirks and complexity around, not that 0-based languages are less confusing, complex, or quirky than 1-based languages, or the other way around. But that said, I'd prefer that Lua had 0-based indexes, simply because that's what most other languages have, not because it's superior.
- chii 5y ago> It's just a matter of moving the confusing quirks and complexity around unless you can exclusively program in 1 language only, these confusions would be the cause of various bugs, or at least, increase the cognitive load. Programming is already hard enough, without artificially increasing the cognitive load!
- CollinEMac 5y agoSame here. It's not a big deal once you get used to it but after years of always having indexes start at 0 it just seems... off.
- throwawayboise 5y agoIf you learned arrays in C where indexing is the same as pointer arithemetic then zero-based arrays seem natural. If you are coming from the real-world concept of "a list of things" then the "zero-th item" in the list seems odd; one-based indexing feels natural.
- _huayra_ 5y agoiirc, one other confusing element is that tables (hash tables? I don't remember what they're called) return null when a lookup is done for a nonexistent key. This is not necessarily a bad choice. Exceptions and such can be a real pain. However, accidentally getting a null value because you didn't check and then have it propagate much further in your program is extremely difficult to debug. Instead of blowing up at the site of the bad lookup, you only see the distant effects of it (e.g. put the null value into another table, which gets put in another table, and then is attempted to be called as a function, etc).
- boardwaalk 5y agoIt even does this for globals (which are just another table), so there’s never an “undefined variable” error (even though there really is). It’s pretty unfortunate. You can mitigate it using meta tables though.
- naasking 5y agoStoring a null value is a legitimate operation. How do you distinguish "never stored a value under key K", and "stored null under key K"?
- scgtrp 5y agoI'm pretty sure you're agreeing with them. Current Lua does this, which is wonky: > t = {} > t['a'] = nil > t['a'] nil > t['b'] nil
- otikik 5y agoGive Teal [1] a look. It’s basically typescript for Lua https://github.com/teal-language/tl https://github.com/teal-language/tl
- otikik 5y agoIf you work with pure Lua that’s a non issue. The ipairs function abstracts that away, and for numerical loops are written different than in C, with a start value (included), an end value (included) and a step (optional), and no exit condition. You can’t put i<len there as a result like you would do in C. Agreed that interaction with C or other 0-based languages or systems (eg screen coords) makes things more difficult.
- fouc 5y agoWhy would Lua be significantly faster than Python? Isn't it an interpreted language too?
- leephillips 5y agoThe JIT version of LUA, according to some benchmarks I just saw, is similar to C in performance.
- harpiaharpyja 5y agoThe Lua interpreter is really lightweight, and for decades has been the go to choice for when you need dynamic code and speed (for example, it's been popular in the games industry for this reason). Probably someone else can shed light on exact numbers, but Lua is faster than Python.
- scruple 5y agoIt's also very small. We used it extensively on embedded Linux devices in the 2000s for these reasons as well as easy interop with C/C++.
- aa-jv 5y agoI'm still using Lua on embedded Linux devices, and in fact completed a project last year that was deemed impossible by the Java devs, but easily within our memory/time budget as a Lua group. The success of that embedded Lua project converted a large number of Java diehards into Lua accolytes... Folks who sniff at putting a scripted/interpreted language into an embedded environment really need to think twice with Lua. It is fast, tight and highly performant - and if you bundle it along with LuaJIT and Turbo.lua, it'll give you the best of all worlds - aynsc i/o, coroutines, very, very fast performance and a great execution environment upon which to build truly useful apps.
- webmobdev 5y agoIsn't it LuaJIT that's really fast? Last I remember reading about it, there was some version fragmentation going on with Lua advancing and LuaJIT stuck on an older version? (That was a long time ago, and I don't know what been happening since.)
- pansa2 5y agoYes, Lua’s now on version 5.4 and LuaJIT is stuck half-way between 5.1 and 5.2.
- DonHopkins 5y agoAnd LuaJIT has historically been extremely fast (initially much faster than JavaScript's early JITs) because it didn't have nearly as many optimizer-busting design flaws to work around as JavaScript JITs did, because Lua's language design is so much simpler and cleaner than JavaScript's, which wasn't originally designed to be compiled (cough cough "with" cough "this"). But because JavaScript was the "Chosen Language", a whole lot of effort has been put into developing JITs that worked around JavaScript's flaws over the decades since. But all that effort could have been put to much better uses if it didn't have all those flaws in the first place.
- deleted 5y ago[deleted]
- BiteCode_dev 5y agoLua definitely does not have the power of something like Python. That's usually what people like about Lua: it's barebone, yet high level and clean. If one likes Python, then the chance of liking Lua are low. E.G: Both python and lua can open something (a file, a socket, a transaction...) in one line. But only Python has the `with` construct that means it's easy to guaranty you close it in case of an error. Lua is then easier to learn: one less concept to master. But the high level tool of Python, that you had to learn, make your life easier. They have very different trade off.
- radlad 5y ago> If one likes Python, then the chance of liking Lua are low. I don't know. I quite like both as well. The design ethos feels similar although Python has certainly added more features over the years.
- BiteCode_dev 5y ago"with" existed in python 2. In python 2.6 in fact, like comprehension lists, decorators, generators, descriptor protocol, exotic slicing assignation, advanced nested unpacking, infinite parameters... Python was always chock-full of advanced features, people just usually don't notice because they get productive in 3 days with the basic features and don't need to go further. It's has the quality of a very smooth learning curve, but a very long one if you care.
- radlad 5y ago"with" and "defer" (Go) are nice but not crucial to me.
- BiteCode_dev 5y agoMy point exactly.
- pygy_ 5y agoLua 5.4 has to-be-closed variables that are similar in functions to with blocks in python. Unkike the __gc hook which provides no guarantee as to when it will be called, if ever, the __close hook is called when a value goes out of scope. http://www.lua.org/manual/5.4/manual.html#3.3.8 http://www.lua.org/manual/5.4/manual.html#3.3.8