Skip to content

proposal: Go 2.0 - Allow the _ character to represent the default value for a given return type when returning from a function. #21422

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

Closed
luke-park opened this issue Aug 13, 2017 · 3 comments
Labels
FrozenDueToAge Proposal v2 An incompatible library change
Milestone

Comments

@luke-park
Copy link

Go clearly defines what the "default" or "zero" value of a type is, whether it be 0, "", false, nil or whatever. With this in mind, consider the following code snippet:

func GetUserInformationFromEmail(email string) (bool, string, time.Time, error) {
    err := someFuncThatCouldRaiseAnError()
    if err != nil { return false, "", time.Time{ }, err }
    ...
}

I propose that we allow the _ character to represent the default, or "zero" value, of a given type when returning from a function. This would amend the original example to the following:

func GetUserInformationFromEmail(email string) (bool, string, time.Time, error) {
    err := someFuncThatCouldRaiseAnError()
    if err != nil { return _, _, _, err }
    ...
}

This change would reduce time spent checking return types and their default values (when I first started learning Go, returning time.Time{ } for an empty time really threw me). I feel this change would also be semantically meaningful with the current uses for the _ symbol.

@gopherbot gopherbot added this to the Proposal milestone Aug 13, 2017
@jimmyfrasche
Copy link
Member

Potential duplicate of #19642

@mvdan mvdan added the v2 An incompatible library change label Aug 13, 2017
@mvdan
Copy link
Member

mvdan commented Aug 13, 2017

This indeed looks like a dup. Let's keep the discussion in that thread. If your proposal has any differences that you think add to the conversation, of course feel free to add them there. Thanks!

@mvdan mvdan closed this as completed Aug 13, 2017
@luke-park
Copy link
Author

I spent so long looking for something similar to this but limited my results to "return types". I knew there would be a duplicate. Thanks for pointing me in the right direction.

@golang golang locked and limited conversation to collaborators Aug 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

4 participants