Closed
Description
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.