You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working in C++, I was recently bitten by having accidentally omitted the closing brace of one if-else statement among many others. The compiler only complained of a syntax error many lines lower down at the beginning of the next function, and it took me a while to find where the problem was, because visually, I normally interpret code by looking at indentation, which matched my intent. On the other hand, the compiler ignores indentation and looks only at braces, which did not match my intent. In this case I got a compile error, but in other cases bad indentation can cause a human to derive a different meaning when reading (syntactically well-formed) code than the compiler does, leading to bugs.
This is the drawback of whitespace-irrelevant syntax: the programmer has to encode the same information in two separate ways, introducing more opportunities to make mistakes. We could have a lint which complains if the "logical" and visual indentations of code don't align to help catch these kind of problems.
The text was updated successfully, but these errors were encountered:
We solve the if-else problem by always requiring braces, but this would still be useful. Not sure it should really be a lint, it feels like something a rustfmt tool would do.
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized.
While working in C++, I was recently bitten by having accidentally omitted the closing brace of one if-else statement among many others. The compiler only complained of a syntax error many lines lower down at the beginning of the next function, and it took me a while to find where the problem was, because visually, I normally interpret code by looking at indentation, which matched my intent. On the other hand, the compiler ignores indentation and looks only at braces, which did not match my intent. In this case I got a compile error, but in other cases bad indentation can cause a human to derive a different meaning when reading (syntactically well-formed) code than the compiler does, leading to bugs.
This is the drawback of whitespace-irrelevant syntax: the programmer has to encode the same information in two separate ways, introducing more opportunities to make mistakes. We could have a lint which complains if the "logical" and visual indentations of code don't align to help catch these kind of problems.
The text was updated successfully, but these errors were encountered: