Skip to content
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

stylecheck: decide fate of CheckIncDec #483

Open
dominikh opened this issue May 18, 2019 · 2 comments
Open

stylecheck: decide fate of CheckIncDec #483

dominikh opened this issue May 18, 2019 · 2 comments
Labels
needs-decision We have to decide if this check is feasible and desirable new-check

Comments

@dominikh
Copy link
Owner

CheckIncDec flags x += 1 and recommends using x++ instead. The check exists, but isn't made available, not even as an optional check. We haven't enabled it so far because it can produce unhelpful warnings for code like the following:

x += 3
...
x += 2
...
x += 1

Either enable the check (optionally with some improvements) or remove it.

@bcmills
Copy link

bcmills commented Jun 1, 2020

Sadly, my related proposal golang/go#21263 was declined. 😉

@mwat56
Copy link

mwat56 commented Jun 9, 2020

@dominikh

Either enable the check (optionally with some improvements) or remove it.

I'd say: remove it.
Using x++ (but, alas, not ++x) in Go is a bit confusing in the beginning if you've worked with ++x and --x in other languages before because it's a statement in Go instead of an expression as in other languages (not to mention the difference between ++x and x++ and what version Go actually compiles to). So you have to re-learn its use anyway in Go and probably end up with x += 1 so that recommending the use x++ wouldn't actually help.
Hence leave it to the programmer and don't interfere with a linter recommendation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision We have to decide if this check is feasible and desirable new-check
Projects
None yet
Development

No branches or pull requests

3 participants