|
|
|
|
|
by jsnell
500 days ago
|
|
The distinction you're not acknowledging is that with pattern matching + algebraic data types you can't do anything with the payload without handling the error case. (You need to write a pattern match to extract the value, and the match needs to be exhaustive.) With a separate error value, like in Go, that's no longer the case. The code for handling the error and the code for doing something with the payload are totally separate, and don't both need to be present. |
|
Consider:
Both returned values are independently observable. Unless you need the error value for your particular situation, the Data variable contains everything you need to know. You can otherwise ignore the error value. Likewise, if all you need is the error value, you can ignore the Data value.Success/failure values are logically intertwined by convention in some other languages, but you can't reasonably take idioms from other languages and slap them down on Go like that. Just as you cannot reasonably do so in reverse. Different languages express things differently. That's what makes them different.
Is that the disconnect here? That you believe all languages share the exact same idioms?