3 ms·
What's so great about `if err != nil` ?
by ciupicri 5y ago
What's so great about `if err != nil` ?
- linkdd 5y agoIn theory: explicit error handling. An error should be taken care of immediately, or propagated with some additional context. Returning the error instead of throw/catch makes this explicit and forces the developer to think about it. In practice: a lot of boilerplate code. Rust does this better with the Result type and the ? operator.
- eyelidlessness 5y agoFrom a pragmatic perspective, the theoretical advantage is real (typed exceptions are better than not having them, just as explicit nullables are better than implicit). Theoretically Result and Option are just recognized names, which I don’t mean to discount but they’re effectively union types with pattern recognition privileges.
- dmitshur 5y agoI like the “opportunity for correction” and “code proportionality” points brought up in https://medium.com/@shazow/code-boilerplate-is-it-always-bad-934827efcfc7 https://medium.com/@shazow/code-boilerplate-is-it-always-bad....