4 ms·
> Six months ago I would have agreed with you. And then I learned about error propagation using the question mark operator in Rust: https://doc.rust-lang.org/bo
by weberc2 8y ago
> Six months ago I would have agreed with you. And then I learned about error propagation using the question mark operator in Rust:
https://doc.rust-lang.org/book/second-edition/ch09-02-recove.. https://doc.rust-lang.org/book/second-edition/ch09-02-recove....
Arguments can be made about creating custom error messages at each call level, but is that really necessary most of the time?
No, this is not necessary most of the time, and I don't consider the "custom error messages" argument to be a very good argument against sugar. The convincing argument in my mind is that unlike Rust, Go has no trait system to facilitate this sugar, so the alternative is to special-case the compiler to support the error type. Of course, Go could implement a trait system, but "error handling sugar" is a negligible factor in whether or not such a system should exist and how it should be designed.
TL;DR--what makes sense for Rust may not make sense for Go.
- jerf 8y ago"The convincing argument in my mind is that unlike Rust, Go has no trait system to facilitate this sugar, so the alternative is to special-case the compiler to support the error type." What do you need out of "traits" that "interfaces" don't provide, for error handling?
- weberc2 8y agoThere isn't infrastructure in the Go compiler for mapping a given sugar to a particular interface. The point isn't traits vs interfaces, but rather that the infrastructure exists in Rust and it doesn't exist in Go (and adding it to Go solely to alleviate a tiny bit of boilerplate is a bad idea).