-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/gofmt: remove plus operator before variable #30299
Comments
gofmt is not a tool that simplifies arithmetic expressions, though. It's a code formatter. Should gofmt also remove the addition in
Braces and semicolons are syntactic tokens. Eliding an unnecessary token and simplify an arithmetic expression are two very different things. |
I agree that this is out of place for plain In fact, If those aren't part of /cc @griesemer |
While we do certain rewrites (and in fact just introduced new ones to canonicalize the formatting of number literals for Go 1.13), we don't want to change what a programmer intended to express in the code. But I admit I don't have a good example except that perhaps one wanted to emphasize a You are correct that removing a unary In fact, one could remove the unary As an aside, note that we cannot easily simplify I'm leaving this open for now for the wider proposal committee to make a decision, but I am leaning against this change. |
Ironically, the floating-point value |
In the following program:
I believe the
+b
is extraneous and does not modify command operation, in both cases. Couldgo fmt
simplify this by removing the plus operator? Similarly we remove things like braces and semicolons when they are unnecessary and do not affect program operation.Running
go
tip.The text was updated successfully, but these errors were encountered: