-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: Go 2: call error handling functions with ... #64399
Comments
Please fill out https://github.com/golang/proposal/blob/master/go2-language-changes.md when proposing language changes |
I don't think it's clear where the conditional branch went? |
Would you consider yourself a novice, intermediate, or experienced Go programmer? |
@seankhliao // before
result1, check...err := Do(param)
// after
_, err := Do(param)
if err != nil {
return check(err)
} |
This seems like another variation on the previous "try" proposal #32437, and it is unclear how it addresses the problems that ultimately caused that proposal to be retracted. Therefore this is a likely decline. Leaving open for a further four weeks for final comments. |
Can you elaborate more on what the unclear is and which the problems are?
And I don't want to push anybody, but we have already spent 5 years on bring error handling to go, how many 5 years we still own? |
@hauntedness To start, your proposal is pretty unclear. You introduce a few functions ( Second, as @alandonovan already mentioned, this doesn't look any better (e.g., more lightweight) from just glancing at the examples (which remain unclear) than many of the error handling proposals that came before this one, so it's not clear why this proposal should stand out above the rest. Finally, Go does have error handling, and it's explicit. It just so happens that in some code that explicit error handling code can be somewhat pervasive, while in other code it's not that pervasive. People who deal with code that have a lot of error handling would like a better solution. Others don't care that much. And again others think that Go's error handling is fine as is. And the split between these groups appears to be somewhat even, making it difficult to push forward an approach that is not obviously superbly better than what we have. And it seems that such an obviously superbly better approach has not yet surfaced (of course, individual authors of error handling proposals may feel differently, but that doesn't matter if not enough people agree). It doesn't seem what you are proposing is obviously superbly better than any of the other proposals that came before this one. Therefore, this proposal remains a likely decline. Thanks. |
Apologize for causing any understanding difficulty. Although I thought It is quite simple and concise, I am glad to provide more explanations. // before
result1, check...err := Do(param)
// after
_, err := Do(param)
if err != nil {
return check(err)
} The
The handle function is used to handle error,
func check(err error) error
func check[T any](err error) (T, error)
func check[T any](err error, otherArgs ...any) (T, error)
Excellent point, I insist not to fix the grammar but this do affect the language in many perspectives. And that's why I don't wish this proposal be closed. It is hard to say affects without enough contributes and I ofcourse welcome for comments.
Please let's forgot just mentioning
Sorry for the inaccuracy words. Yes, agree with most of the comments. I know it is hard to reach consesus, I wish we can achieve it quickly while I also understand how hard it is. But from my point, we'd better encourage ideas rather than do nothing. |
Per // before
result1, check...err := Do(param)
// after
_, err := Do(param)
if err != nil {
return check(err)
}
I also point out that the use of But separately, the syntax you're implying with your examples is unlike anything else we have in Go. There's no convincing argument why this is any better than any of the many other error handling proposals. |
check...err is translated into the "after" code, is that correct? Can I write something else than check? Can I write foo...err (and define a foo function)? These are things that all need to be clarified. |
No change in consensus, so declined. |
Proposal Details
In the current Golang language, error handling requires the use of if statements and return values to check and handle errors. While this approach is effective, it introduces a lot of repetitive code and redundant error handling logic in the codebase. To simplify the error handling process, improve code readability, and maintainability, we propose enhancing the error handling syntax sugar in Golang to make it more concise and flexible.
Background:
In the existing Golang language, error handling is typically done as follows:
This approach requires the use of if statements and return values to check and handle errors, resulting in a lot of repetitive code and redundant error handling logic. To simplify the error handling process, improve code readability, and maintainability, we propose enhancing the error handling syntax sugar in Golang.
Proposal:
We propose introducing the following new syntax sugar to simplify error handling in Golang:
Apologies in advance for any lack of thoroughness, any suggestion is appreciated.
The text was updated successfully, but these errors were encountered: