News for hackers. Stuff that matters.
Re:Go Is a Well-Designed Language by murderfs on Friday January 31, 2025 @02:58AM (#42885534)
Does it make sense for every function to have those four cases, though?
Re:Go Is a Well-Designed Language by frou_dh on Friday January 31, 2025 @03:56AM (#42885867)
This is why it's table stakes for a half-decent type-system to have both product-types and sum-types. They are both sides of the coin and you use the one that actually makes sense for the code being written.

A justification for Go's deficient type-system I've seen repeatedly over the years, along the lines of "Well actually the occasional function can return both a result AND an error" is nonsensical. It's basically excusing giving 98% of error-returning functions a semantically wrong return type (a tuple) because it happens to be correct in 2% of cases.

Every function should have a semantically correct return type! If a product-type is occasionally correct for an error-returning function, use one just for those functions! And use a sum-type for the other 98% where it is semantically correct for them!

Re:Go Is a Well-Designed Language by noelwelsh on Friday January 31, 2025 @03:03AM (#42885560)
Exactly. One can think of examples where these cases make sense, but there are many more examples where there are more cases (e.g. there many be multiple kinds of partial successes) or fewer (most functions, which either succeed or fail.)

Also, the design requires null values. A point which the replies have ignored.