logoalt Hacker News

9rxlast Tuesday at 5:37 PM2 repliesview on HN

In Go, values are to be always useful, so `result | error` would be logically incorrect. `(result, result | error)`, perhaps – assuming Go had sum types, but that's a bit strange to pass the result twice.

Just more of the pitfalls of it not being clear how Rust-style applies to an entirely different language with an entirely different view of the world.


Replies

JamesSwiftlast Tuesday at 5:41 PM

What is useful about the value of `x` in the following code?

  x, err := strconv.Atoi("this is invalid")
On the contrary, `x` is _lying_ to you about being useful and you have absolutely no idea if the string was "0" or "not zero"
show 2 replies
kiitoslast Tuesday at 8:49 PM

If a function `func foo() (int, error)` returns a non-nil error, then the corresponding `int` is absolutely invalid and should never be evaluated by the caller, unless docs explicitly say otherwise.

show 1 reply