5 ms·
There are a bunch of reasons why this is more of an issue in JavaScript than it is or would be in most languages. The early incarnations of the language practic
by stormbrew 4y ago
There are a bunch of reasons why this is more of an issue in JavaScript than it is or would be in most languages. The early incarnations of the language practically leaned into bad parsing logic and it's permanently stuck with them now.
But in particular any strongly typed language is gonna need some really convoluted code to produce similar ambiguities that actually make it to linking.
I think the most likely "bad" outcome of semicolon-less rust would be losing the hanging dot function chaining people do so much in rust, but even that's not a guarantee.
- srcreigh 4y agoThis was almost prevented from the get go. Brendan Eich tried to implement scheme in the browser. But the business people asked him to make it look like Java. :(
- littlestymaar 4y ago> But in particular any strongly typed language is gonna need some really convoluted code to produce similar ambiguities that actually make it to linking. Even if it's a compiler error, what are you supposed to do when the compiler returns the error from the snippet above?
- stormbrew 4y agoI think you'll need to come up with an example that exploits a weakness in rust's grammar for me to answer that? The above js example I don't think it would make sense to have rust erase the newline to begin with.. I think the main way that people hang syntax like this in rust is with chained .methods, and since . at the start of a statement isn't valid rust to begin with it could probably be unambiguously be allowed anyways. But I wouldn't expect: a [1] To be considered valid specifically because of the potential ambiguity of a single term array and a suffix index. It's also not really common right now anyways, afaik. JavaScript tries to be way too damn clever here and no one is ever going to seriously suggest anything try to replicate "automatic semicolon insertion". Just don't allow line joins when it makes the next line ambiguous. Interestingly it would be possible to come up with a straw man parser that makes semicolons optional and then run it through the whole "recompile every crate" thing the rust project has to see if it would cause new failures. It would be an interesting project tbh.
- Asraelite 4y agoIt's a problem in Python too, but in the opposite direction in that Python is too eager to parse multiple lines as multiple expressions instead of a single expression, forcing you to add parentheses everywhere. 1 + 2 is a syntax error, you need to make it 1 + ( 2)