-
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: Go2: try: Change try() proposal to use a special character in the position where an error is returned #32884
Comments
This has been suggested many times. See #32500 and It even appears a few times within the comments on |
This seems quite cryptic for people unfamiliar with Go. That's not a fatal problem, but it is a cost. |
It was also suggested at #32601 which used Although I personally prefer #32437 for the reasons stated there, I do think this is one of the better alternative proposals. Points in its favor include:
However, it is cryptic and those who object to |
I have 2 main concerns. This eliminates the ability for error decoration and it always implicitly returns. I often return an error, but sometimes I just log it or |
@mvndaai Having this feature does not preclude the standard |
@integrii I agree that is doesn't stop the current pattern from working, but it does mean that there is another pattern. My biggest issue with go errors is when I have
Which is annoying to do and my function scope gets polluted with a long-living I am worried adding a third way to handle errors would mean I would end up doing even more refactors. |
The |
There were no further comments. |
It looks like #32437 is the current most popular error handling proposal. This proposal wishes to introduce a
try()
statement that returns the default values of all return variables if a value other thannil
is returned as the last value from a function. In normal function, thetry()
statement returns all values that are not the final error value.How about instead of wrapping things in parentheses all over the place, we directly put a special key (like
!!
or anything else) into the place where the error is returned? That's shorter and all other behaviour is the same. Also, you don't have invisible returns here, or require the error to be the last thing returned.This also discourages changing try statements together which keeps code more readable.
The text was updated successfully, but these errors were encountered: