4 ms·
> Adding tuples (value, error) Like https://godoc.org/net/http#Get https://godoc.org/net/http#Get?
by weberc2 10y ago
> Adding tuples (value, error)
Like https://godoc.org/net/http#Get https://godoc.org/net/http#Get?
- nine_k 10y agoReturning multiple values is the norm. But these values are immediately unpacked, cannot be passed around as a whole, or have methods. It would be great to have something like a conditional return to get rid of the endless `if err != nil`, or, while we're at it, from endless `.then` that futures-based programming ends up with: foo_result, err = foo(...) on_failure(err, "foo failed") bar_result, err = bar(foo_result, ...) on_failure(err, "bar failed though foo did not") return bar_result + 1
- deleted 10y ago[deleted]
- weberc2 10y agoI've never found `if err != nil {` to be a problem; on the contrary, it draws my eye right to the error-handling logic in any function. OTOH, exceptions tend to obscure this (in the best case you have checked exceptions and you are only unsure about which function is raising the exception; at worst you have something like Python where you have no idea what exceptions could be thrown or if they're handled properly), and Rust's `try!` tends to blend in too well with its surroundings (this is a special case of Rust's density making it hard to read). YMMV.