Skip to content

proposal: return sugar #14066

Closed
Closed
@gertcuykens

Description

@gertcuykens

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions