3 ms·
I think there's an easy solution to this, would love to know if I'm off track: postfix `catch` optionally captures the last value in the return tuple. Instead
by deagle50 3y ago
I think there's an easy solution to this, would love to know if I'm off track: postfix `catch` optionally captures the last value in the return tuple.
Instead of
value, err := foo();
if err != nil {
// handle err
};
you get
value := foo() catch err {
// handle err
}
- otteromkram 3y agoWe have: if value, err := foo(); err { // do something with err. } else { // do something with value. }
- deagle50 3y ago"else" for the happy path is part of the problem.
- neilwilson 3y agoGenerally in Go the error path is part of the if, which usually returns from the function. Then the 'happy path' is just the rest of the function. If you end up with complexity at this point then it is time to refactor into several functions so the 'happy path' follows the standard idiom. Consider it a Go code smell.
- deagle50 3y ago> Then the 'happy path' is just the rest of the function. Right, and that's why it's bad.