5 ms·
C++ compilers massively improved their error messages in the last couple decades. If you were missing a semicolon, it used to give you some syntax error when i
by jdlyga 5y ago
C++ compilers massively improved their error messages in the last couple decades. If you were missing a semicolon, it used to give you some syntax error when it tried to parse the next statement. Now, it just tells you that you forgot a semicolon. These kinds of user friendly improvements really make compilers easier to work with.
- loloquwowndueo 5y agoIf it can tell you forgot the semicolon it probably can do without it, so why doesn’t it? ;)
- astura 5y agoJavaScript has automatic semicolon insertion and I'm not a fan
- dudeman13 5y agoAh, but are you not a fan because of the automatic semicolon insertion or because... well, JavaScript :P
- junon 5y agoBecause it's a massive headache to debug code that has subtle bugs due to missing semi-colons.
- williamdclt 5y agoNever happened to me TBH. There's very few cases where the semicolon is actually significant, and when it happens my autoformatter produces garbage which makes it very obvious, or it adds the semicolon itself. That doesn't mean it never happens (most of us inherited a shitty codebase lacking things like code standards and autoformatting at some point), but I always find it strange that people keep talking about this thing I've never experienced in years writing JS professionally
- zabzonk 5y agog++ (and I assume other compilers) may diagnose it as missing either a comma (because of the comma operator) or a missing semicolon (can't find the end of statement) - silently providing one or the other would not be a good idea. Actually, I remember Jerry Pournelle asking exactly the same question about Pascal in Byte magazine in the 1980s.
- bookofsand 5y agoAmbiguity. 95% of the cases you forgot the semicolon, the other 5% you forgot something else.
- teeray 5y agoIt’s better, but I still would love to see the amount of vomitus reduced when templates are involved.
- flafla2 5y agoConcepts will help a lot with this. I think a large reason that template errors are/were hard to parse is that SFINAE is fundamentally hard to read for humans (but is relatively simple for the compiler to figure out)
- vinayan3 5y agoThe way suggestions come out lead to a lot of verbosity for C++ compilers when reading in a console. Template errors have gotten better but can get very verbose. I rarely read the whole thing. You learn how to skim and find where I can click to get to the line which has the issue.
- yissp 5y agoA missing brace or parenthesis still often leads to pretty confusing error messages, I find. I don't know much about parsers, though, maybe that's just a really hard thing to deal with.
- estebank 5y agoThere are multiple problems that missing delimiters introduce for the parser when trying to recover. It depends heavily on the language's valid grammar how much you can infer about malformed code to identify likely places where the missing delimiter should go. One thing you can do (that Rust does) is keep a stack of opened delimiters and their positions, and pop them as you find the closing one. If you encounter a mismatch or any other parse error, you look through the open delimiters to match for indentation level or valid alternatives. The more "flag posts" or redundancy the grammar has, the more likely you are to be able to recover from malformed code. If you are in a language with a sparse grammar, recovery is less feasible.
- Someone 5y agoC++ is very hard to parse. For non-parseable C++, it is even harder to recover, that is, figure out where to restart parsing. The classic example is forgetting to end a typedef struct foo with a semicolon, at the end of an #include file. The compiler will happily combine that with whatever follows the #include# statement in the file including it, and report an error with a line number in the file doing the #include.