9 ms·
> sorry, not to nitpick, but I am really not a fan of one-based indexing It is very funny how this is just the one sole criticism that always gets brought up.
by ADeerAppeared 2y ago
> sorry, not to nitpick, but I am really not a fan of one-based indexing
It is very funny how this is just the one sole criticism that always gets brought up. Not that other problems don't exist, but they're not very talked about.
Lua's strength as a language is that it does a lot quite well in ways that aren't noticeable. But when you compare things to the competition then they're quite obvious.
E.g. Type Coercion. Complete shitshow in lots of languages. Nightmare in Javascript. In Lua? It's quite elegant but most interestingly, effortlessly elegant. Very little of the rest of the language had to change to accomodate the improvement. (Excercise for the reader: Spot the one change that completely fixes string<->number conversion)
Makes Brendan Eich look like a total clown in comparison.
- PicassoCTs 2y agoOne based indexing is also the one thing every beginners course has to hammer into people, as its so non-intuitive until you know about pointers.
- taberiand 2y agoTo be fair, having to work with 1 based indexing when you're used to 0 would be a frustrating source of off-by-one errors and extra cognitive load
- opticfluorine 2y agoEspecially when one of the language's main purposes is to be embedded in applications written in other languages (which are predominantly zero based) - and so you tend to have a lot of back-and-forth integration between these two styles that can get confusing. Even from the C API side, for example, the Lua stack is one-based but addressed exclusively from the host language which is likely zero-based.
- berkut 2y agoAs someone who's used Lua a lot as an embedded language in the VFX industry (The Games industry wasn't the only one that used it for that!), and had to deal with wrapping C++ and Python APIs with Lua (and vice-versa at times!), this is indeed very annoying, especially when tracing through callstacks to work out what's going on. Eventually you end up in a place where it's beneficial to have converter functions that show up in the call stack frames so that you can keep track of whether the index is in the right "coordinate index system" (for lack of a better term) for the right language.
- fp64 2y agoOh that’s super interesting, where in the VFX industry is Lua common? I typically deal with Python and maybe Tcl (I do mostly Nuke and pipeline integrations), and I can’t think of a tool that is scripted in Lua. But I’ve never worked with Vega or Shake or what this is/was called
- berkut 2y agoKatana uses LuaJIT quite extensively for user-side OpScripts, and previously both DNeg and MPC (they've largely moved on to newer tech now) had quite a lot of Lua code...
- fp64 2y agoOh, I had no idea! I don’t have much to do with Katana, I just assumed it was also all python
- berkut 2y agoIt used to in older (pre 2.0) versions, but due to Python's GIL lock (and the fact Python's quite a bit slower than lua anyway), it was pretty slow an inefficient using Python with AttributeScripts, so 2.0 moved to Lua with OpScripts...
- chengiz 2y agoIt absolutely is. For a language whose biggest selling factor is embeddability with C/C++, that decision (and I'm being polite) is a headscratcher (along with the other similar source of errors: 0 evaluating to true).
- usrusr 2y agoIt's the perfect distraction: once you start accepting one-based, everything else that might be not quite to your liking isn't worth talking about. I could easily imagine an alternative timeline where lua was zero-based, but never reached critical mass.
- wruza 2y agoAbsolutely so. It’s just one obvious thing from a large set of issues with it. One can read through “mystdlib” part of any meaningful Lua-based project to see it. Things you’ll likely find there are: NIL, poor man’s classes, __newindex proxying wrapper, strict(), empty dict literal for json, “fixed” iteration protocols. You don’t even have to walk too far, it’s all right there in neovim: https://neovim.io/doc/user/lua.html https://neovim.io/doc/user/lua.html
- kragen 2y agoThis is very valuable! Thank you!
- usrusr 2y agoPerhaps that's the secret to lua's success: they got the basics so wrong that they can't fall into the trap of chasing the dream of becoming a better language, focusing on becoming a better implementation instead. Or perhaps even more important: not changing at all when it's obviously good enough for the niche it dominates.
- kzrdude 2y agoThat's an interesting notion but I think that Lua had no competition - it was almost unique in how easy it was to integrate vs the power it gives. Its popularity was inevitable that way.
- bigstrat2003 2y agoI don't really blame Lua for that, though. 1-based indexing comes naturally to humans. It's the other languages which are backwards. I get why other languages are backwards from human intuition, I do. But if something has to be declared the bad guy, imo it's the paradigm which is at odds with human intuition which deserves that label, not the paradigm which fits us well.
- saurik 2y agohttps://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831... Why numbering should start at zero. -- Dijkstra
- MattJ100 2y agoI admire Dijkstra for many things, but this has always been a weak argument to me. To quote: "when starting with subscript 1, the subscript range 1 ≤ i < N+1; starting with 0, however, gives the nicer range 0 ≤ i < N" So it's "nicer", ok! Lua has a numeric for..loop, which doesn't require this kind of range syntax. Looping is x,y,step where x and y are inclusive in the range, i.e. Dijkstra's option (b). Dijkstra doesn't like this because iterating the empty set is awkward. But it's far more natural (if you aren't already used to languages from the 0-indexed lineage) to simply specify the lower and upper bounds of your search. I actually work a lot with Lua, all the time, alongside other 0-indexed languages such as C and JS. I believe 0 makes sense in C, where arrays are pointers and the subscript is actually an offset. That still doesn't make the 1st item the 0th item. Between this, and the fact that, regardless of language, I find myself having to add or subtract 1 frequently in different scenarios, I think it's less of a deal than people make it out to be.
- Certhas 2y agoAnd the reason to dismiss c) and d) is so that the difference between the delimiters is the length. That's not exactly profound either. If the word for word same argument was made by an anonymous blogger no one would even consider citing this as a definitive argument that ends the discussion.
- opticfluorine 2y agoIt is funny, isn't it? I always wonder how the language would be perceived had they gone with zero based indexing from the start. I'm a big fan of Lua, including for the reasons you mention. I suspect the reason this one thing is always brought up is twofold: it's easy to notice, and it's very rare these days outside of Lua (if you consider VB.NET to be a legacy language, anyway). Other criticisms take more effort to communicate, and you can throw a rock and hit ten other languages with the same or similar issues.
- sitkack 2y agoDon't forget that not equals is ~=, the horror. The real gripes should be globals by default and ... nothing. Lua is wonderful.
- gerdesj 2y ago"Don't forget that not equals is ~=, the horror." I get you are taking the piss but ~= is just as logical as != being the symbols for: "not equals", if you've been exposed to some math(s) as well as ... well, ! means factorial, doesn't it? Syntax is syntax and so is vocabulary! In the end you copy and paste off of Stack Exchange and all is golden 8)
- ctippett 2y agoI'm more familiar with CSS than I am with Lua. The syntax for the former has a very different meaning[1]. [attr~=value] Represents elements with an attribute name of attr whose value is a whitespace-separated list of words, one of which is exactly value. [1] https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#attrvalue_2 https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_s...
- bingo3131 2y ago! is commonly used as the unary not operator, so "a != b" makes sense as a shortcut for "!(a == b)". a not equals b.
- xigoi 2y agoBut in Lua, the unary not is written as “not”.
- astrobe_ 2y agoFor a language apparently inspired from Wirth, one would have expected <> (greater-or-lesser-than). But the real horror, to me, is Windows not letting one disable the so~called "dead keys" easily.
- kps 2y ago
- saghm 2y agoHonestly, it might almost act as a "honeypot" to give people a convenient target to complain about, which makes it easier for the rest of the language to get viewed as a whole rather than nitpicked. Sometimes I think people like to have at least one negative thing to say about something new they learn, whether it's to show that they understand enough to be able to find something or it's to be "cool" enough not to just like everything.
- chii 2y agothat would be a galaxy brain move on the part of lua.
- saghm 2y agoTo be clear, I'm not claiming that I think this was the original intent for implementing array indexes like this; I'm just theorizing that this might explain why this ends up being such a fixation when it comes to discusses downsides of Lua.
- krapp 2y ago>Makes Brendan Eich look like a total clown in comparison. To be fair, Brendan Eich was making a scripting language for the 90's web. It isn't his fault Silicon Valley decided that language needed to become the Ur-language to replace all application development in the future.
- thaumasiotes 2y agoWasn't the language he was making for the web Scheme?
- hollerith 2y agoNo, Scheme was defined in 1975.
- thaumasiotes 2y agoSo? That doesn't stop Brendan Eich from putting it in a web browser 20 years later.
- hollerith 2y agoNo, it does not. I see I misunderstood your q.
- yoz 2y agoMost of the blame should go to Netscape management. They didn't give Eich much time, then burst in before he was done and made him copy a bunch of things from Java. (The new language, codenamed "Mocha" internally, was first publicly announced as "LiveScript", and then Sun threw a bunch of money at Netscape.) IIRC, Eich was quite influenced by Python's design. I wish he'd just used Lua - would likely have saved a lot of pain. (Although, all that said, I have no idea what Lua looked like in 1994, and how much of its design has changed since then.)
- BrendanEich 2y ago