4 ms·
I never tire of comparing Lua with Javascript, and this is another one of those cases. A semicolon in Lua is simply a character which is illegal to place anywhe
by samatman 12y ago
I never tire of comparing Lua with Javascript, and this is another one of those cases. A semicolon in Lua is simply a character which is illegal to place anywhere but the end of a statement.
There is no insertion stage, the language parses just fine on a single line, or any whitespace you choose. Semicolons are vanishingly uncommon in Lua code, but if you want to compress a couple statements onto a line, they signal your intention.
Lua is like what Javascript would be if it were: based on Pascal, written by resource-constrained Brazilians, and capable of making backwards-incompatible changes. Though with the de-facto fork between Lua and LuaJIT, the latter has become much more difficult, as it should at some point in the maturing of a language.
- outworlder 12y agoRegarding the resources, we have companies with ridiculously large pockets using Lua, which could contribute more. Think Blizzard. WoW uses Lua heavily. Though I suspect that niche will eventually be taken away from Lua too, which is unfortunate.
- ioddly 12y agoIf anything, Javascript suffered because it had large corporations invested in it. The guys at PUC-Rio were never beholden to corporate sponsors as far as I know, and thus free to break compatibility.
- outworlder 12y agoThat may be true. But without corporate backing, we wouldn't have had so many amazing implementations, which helped with the adoption. Even if Lua (or Lua-JIT) can still beat the crap out of them sometimes. Back then there wasn't even a contest.
- BrendanEich 12y agoWhy does corporate sponsorship have anything to do with it? Any browser that gained non-trivial market share would have felt the same "don't break the web, or you lose market share" pain that the bigs felt. KHTML only started getting adoption via the Safari fork because Dave Hyatt and others implemented real-world quirks (e.g., residual style), prior to webkit.org. Gecko had the benefit of `if (document.all) { IE code here } else { Netscape code here }` patterns from the '90s, but we had to add quirks to gain share with Firefox (m/b, then Phoenix) in 2002 and onward: innerHTML, undetected document.all emulation, and of course XHR. Corporations have nothing to do with it. Any evolving ecosystem with a huge corpus of popular content begets terrific selection pressure against breaking backward compatibility.
- tedunangst 12y agoI'm not sure Lua is that different than Javascript here. What is a semicolon in Javascript if not a character you can only place at the end of a statement? There are some similar ambiguities in the Lua parser if you insert a newline into the middle of a statement. The difference is that Lua is quite a bit fussier about statements versus expressions, and won't allow things like "x() or y()" as statements. So the Javascript example, translated to Lua, wouldn't compile with or without a semicolon.
- karma_fountain 12y agoYou can also place a ';' in the for loop, eg for(;;){ }
- tedunangst 12y agoThose are arguably equivalent to statements, but fair point. Not sure it matters in the Lua vs JavaScript comparison.
- samatman 12y agoThere are no such ambiguities. Here is the complete Lua grammar. You may confirm for yourself that semicolons are always optional and that newlines have no semantic meaning. http://www.lua.org/manual/5.1/manual.html#8 http://www.lua.org/manual/5.1/manual.html#8
- tedunangst 12y agox = fn (y) Insert a newline: x = fn (y) Syntax error. What happened? The newline has no semantic meaning.
- samatman 12y agoYour problem is not what you think! Quite.... print(foo) ("x"):len() This creates the same error. Deleting the newline gives you a new, different error. A semicolon give the correct behavior. It's the edge case that the Lua grammar can't resolve, and it does the sensible thing, by refusing to compile. Also note that it is a compile-time error that is described as an ambiguity. It isn't a silent thing that bites you later, as in Javascript, and the difference is huge. [added] I'm not sure what you mean re "x() or y()" the following compiles fine: function t() return true end function f() return false end if t() or f() then print "logic" end and does indeed print "logic".