3 ms·
I agree it’s be nice to be able to return error + zero values in a simpler way. Personally I think they should add a keyword like returnif or check to do this,
by grey-area 4y ago
I agree it’s be nice to be able to return error + zero values in a simpler way.
Personally I think they should add a keyword like returnif or check to do this, as sometimes (maybe half the time?) you don’t need to decorate an error if you want to handle it higher up. So you could just do:
returnif err
I hate the guard proposal as it mixes up error handling and function calls, but it’d be nice to have a simpler less verbose way to return errors.
In comparison with languages throwing exceptions though, Go is far far easier to reason about, even if more verbose.
- kitd 4y agoreturnif err That's exactly his proposal at the end of the article, except he uses 'guard' as the keyword.
- grey-area 4y agoSorry, was commenting on the guard proposal not the article but yes you’re right about the article reiterating this but with 'guard' - this is an old idea that multiple people have proposed over the years usually with returnif or similar as the keyword. Very confusing that he tried to repurpose ‘guard’ for something which is just a return.