|
|
|
|
|
by wlamartin
1683 days ago
|
|
> The only thing that's different is that you get a single value you have to check for errors rather than a separate value.. The type system confines you to a set of reasonable cases that allow a caller to reason about the state of the program. This has two benefits for the caller: 1. It is required that the caller check whether a return value is success or failure in order to access the value they want. There is no possibility to mistake one case for another. 2. In the space of valid return values for idiomatic Go function signatures, 50% of them are unidiomatic and end up being ignored. It is far clearer for a caller to understand what is expected of them when valid values exactly overlap with the space. It is far clearer for an author to convey expectations to a caller for the same reason. Now I must admit, good conventions and tooling in Go account for the vast majority of cases and I don't personally mind that much, but that's a different conversation than API design. |
|