3 ms·
The error handling in Go seems verbose: if err = logit(FrobulatingMessage); err != nil { return err } if err = f.cleanupOldest(); err != nil
by Animats 9y ago
The error handling in Go seems verbose:
if err = logit(FrobulatingMessage); err != nil {
return err
}
if err = f.cleanupOldest(); err != nil {
return err
}
There's an advantage, though. You can easily insert code for an error case. You might add, if cleanupOldest fails, something like
logError("cleanupOldest failed unexpectedly while cleaning up chain")
if that's an unlikely but possible event that needs to be investigated. Big operational shops do that. It's hard to stick debug code in the middle of an expression.
- deleted 9y ago[deleted]
- TheDong 8y agoThe equivalent in rust, for a fair comparison: Before: frobulate(message)?; After: frobulate(message).map_err(|e| { error!("error happened: {}", e); e })?; // or, more like the go one if let Err(e) = frobulate(message) { error!("error: {}", e); return Err(e); } It's really not that different in the debug case than go, but the normal case is less painful to deal with.