-
Notifications
You must be signed in to change notification settings - Fork 17.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: improved nil checking #33115
Comments
This would make it too easy to accidentally confuse |
I think this wouldn't be too confusing because most of the time instead of |
@Terottaja, if the caller mistakenly writes |
This looks like a duplicate of #21769, which was declined. |
Seems like that definitely could be done, But could be also evaluated because usually people don't write |
Is it really worth losing the explicitness of I would rather have the That would make |
The
They reduce readability. |
I have to agree with @mvndaai that this proposal risks diluting the clarity of the language and making it behave more like ECMAScript (JavaScript). I really don't think it should go in that direction. However, if a special operator like the |
could also use ? since its not being used anywhere else |
@Terottaja the How do you propose the syntax would look? prefix or postfix? |
Also, the only other situation that needs to be made clear is how to use the not Should this support operator inversion and how. |
How do you propose the syntax would look? prefix or postfix? |
If it is readability you are after, you could consider to add a private has() function to your package:
You can then rewrite your example like:
Like: https://play.golang.org/p/MSBQbytsi61 Obvious downside is that you have to redeclare the 'has' function in every package where you need it. |
The |
So, first revised proposed syntax: if ?err {
panic("Error occurred.")
} Votes please. |
or second revised proposed syntax: if err? {
panic("Error occurred.")
} Votes please. |
Or split up #33152 since it contains several issues in one. |
I wouldn't say that #33152 is being kept open as such. I would say that we haven't gotten to it yet. |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?win 8.1 amd64
go env
OutputProposal for C Style nil checking
Instead of
you could write
i think this would free up a lot of if err != nil clutter kind of how for {} is and also if statements with multiple nil checks and that this would be great with having to write less and being more productive with Go. If anyone has any better ideas i would like to hear them too to hopefully improve Go as the language evolves and this could be even applied to any other type if they can be nil
The text was updated successfully, but these errors were encountered: