-
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
Proposal: spec: Bang! notation for error handling boilerplate #21155
Comments
Multiple similar proposals have been made in the past, e.g. #16225. What sets your proposal apart? If you can't answer that question, it will likely be declined. |
Looking through the Go2 issues, #18721 looks closest modulo the proposed here ! syntax. The change is backwards compatible with Go1 and has clear semantics since it's only syntax sugar for the tons of |
Even if it's backwards compatible, such big changes to the language are not being considered for 1.X. If you look at the last few major releases, very few language changes have been made - and they were all very small. |
Having the control flow of the function disrupted by a tiny, one-character, 1-pixel-wide, almost invisible symbol placed in the middle of the line is not a good idea, IMO. They did that in Rust: they had the In my opinion, syntactic sugar that changes the control flow of the code should be much more prominent on the screen. At least a whole keyword, and certainly not placed in the middle of an otherwise plain-looking line of code. |
I agree, |
Sounds like repetitive pattern is something wrong per se. I don't think so. Error handling is critically important from the correctness POV (I know I'm repeating myself from elsewhere). The desire to make important code less visible, or almost invisible as in this proposal, is IMO a mistake. |
I agree with you that "error handling is repetitive but critically important". I see it the other way around: "error handling is critically important but repetitive" and this should be addressed. Coming from Haskell where error handling is entirely implicitly handled by the |
Well, if Go, Rust and Haskell will do the same and even look the same - why should they exist as different PLs? ;-) A better articulation of the above: https://www.youtube.com/watch?v=rFejpH_tAHM (much recommended if you've not seen it already.) |
This is a known topic of discussion and this specific proposal is very similar to other proposals that have been made in the past. I'm going to close this one in favor of the general discussion that should happen in the context of Go 2 thinking. |
Proposal
Add
p, q = foo!(a, b, c)
notation equivalent toto reduce error handling boilerplate code.
This can simplify great amount of code and make it more readable and composable while preserving the full power of idiomatic error handling in Go. For example
becomes
or even
The text was updated successfully, but these errors were encountered: