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

proposal: return sugar #14066

Closed
gertcuykens opened this issue Jan 22, 2016 · 4 comments
Closed

proposal: return sugar #14066

gertcuykens opened this issue Jan 22, 2016 · 4 comments
Labels
error-handling Language & library change proposals that are about error handling. FrozenDueToAge Proposal

Comments

@gertcuykens
Copy link
Contributor

I looked around and didn't find any tickets about it, but what about a little bit of sugar for a optional auto return values as soon as there are assigned and none of them is nil using the following syntax?

// returns err if not nil
func example()  error {
     dat, !err := ioutil.ReadFile("/tmp/dat")
     ...
}
// returns (x, y) if none of them is nil
func split() (int, int) {
    !(x, y) := 6, 5
    ...
}

Which unclutters the code allot when you have many return's in a function http://play.golang.org/p/2kEKXq-kUV

@bradfitz
Copy link
Contributor

This has been proposed in dozens of forms ad nauseam here and elsewhere. Even if this were to go through the https://golang.org/s/proposal-process, I have no belief it would fare better than the previous proposals.

For previous proposals, I see at least 8 searching the golang-nuts mailing list for "error handling sugar".

@gertcuykens
Copy link
Contributor Author

ok :) ps it's a more general return proposal actually not just error's

@gertcuykens gertcuykens changed the title go: return sugar proposal: return sugar Jan 22, 2016
@bradfitz
Copy link
Contributor

You're more than welcome to write a formal proposal using https://golang.org/s/proposal-process but the bar for language changes at this point is pretty much impossible (and has been for years), so you'd have to be very convincing with lots of data to back you up on how this would affect Go programs out there.

@gertcuykens
Copy link
Contributor Author

Understandably so :) you don't want to have a python 2, 3 scenario. I couldn't see any issue for breaking current syntax but I am not a expert. Anyway will ask for more expert advice. https://forum.golangbridge.org/t/proposal-return-sugar/1858

@golang golang locked and limited conversation to collaborators Jan 23, 2017
@seankhliao seankhliao added the error-handling Language & library change proposals that are about error handling. label Jan 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
error-handling Language & library change proposals that are about error handling. FrozenDueToAge Proposal
Projects
None yet
Development

No branches or pull requests

5 participants