Re:Go 1.8 Release Notes
by prodigal_erik on Thursday February 16, 2017 @06:17PM
(#13664525)
Even a special-case Result<T, E> in the language would be far more useful than multiple return values simply because you could pass it through a channel or a slice.
> Adding tuples (value, error)
Returning 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 + 1I'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.
But that would require either more special-case magic (always bad), or generics (not in 1.x, supposedly).