|
|
|
|
|
by amscanne
1834 days ago
|
|
> In contrast, a product type says "I have both a result and an error", which makes no sense As an aside, there are many situations where this does make sense. Consider even the lowly Write, which returns (int, error). On a partial write, you will get the number of bytes written successfully (the result) and the error encountered. I agree that most result/errors are sum types, but part of the philosophy of Go the programmer is ultimately in charge, and that while types are important, they can’t substitute for an actual understanding of the semantics of a given function call, etc. For example, even if Write was a sum type, what would a result of zero mean? So while there’s value in reducing the invalid states that representable, there’s also diminishing returns. So the question is where to draw the line in the language. I agree that having sum types would be convenient, but I’m not sure that Go has made the wrong choice here, given that it seems to have found a really productive balance. |
|