3 ms·
Go has "defer", which is great. Perhaps it should have a similar "whenever" construct. val, err := foo() if err != nil return err vee, err
by kevhito 10y ago
Go has "defer", which is great. Perhaps it should have a similar "whenever" construct.
val, err := foo()
if err != nil
return err
vee, err := bar()
if err != nil
return err
Would become:
var err error
whenever err != nil
return err
val, err := foo()
vee, err := bar()
Static analysis would insert the appropriate check any time err is assigned in the function. Aliasing might be a gotcha, but I'd bet that is a rare case and static escape analysis could maybe catch it and either error, or just insert extra checks.
- deleted 10y ago[deleted]