-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Require whitespace on both sides of - or neither #7399
Comments
That was fast 😄 |
Yep! Easiest way to get a proposal accepted is to (1) solve a footgun
I'd say all, for consistency, but feel free to make a case for just Tasks to close the issue:
|
I have a question related to this and #35, is |
Linear / polynomial equations are often written using + to make the coefficients clear... So what about |
That's fine, the |
No, zig fmt would fail to parse it. If it "fixed" it then it would re-introduce the footgun. |
If all operators are required to have mandatory space around, it would increase readability and also allow to use - (minus) as name character. Where such requirement would really shine are long names: |
…ixes ziglang#7399 This change also moves the warning about "&&" from the AstGen into the parser so that the "&&" warning can supersede the whitespace warning.
This may be out of scope for the language, but it's in line with other accepted proposals like #35 and #114 which aim to avoid misinterpretation.
Here's an example of the problem this prevents:
See the bug? It took me a minute.
View Answer
Here the `,` is missing from the third item in the list. This makes the list 7 items long instead of 8, and the third item `-pitch+1-1`. If you look closely, you can see that GitHub's syntax highlighting parser actually identifies the bug, and gives the `-` on line 4 a different color to indicate that it's not unary.My proposal to solve this is to require whitespace either both before and after
-
, or neither before nor after. We may also want to apply this to other operators for consistency, but I think-
is the one that really causes problems. Here are some examples under this rule:The text was updated successfully, but these errors were encountered: