News for hackers. Stuff that matters.
Re:Go Is a Well-Designed Language by noelwelsh on Friday January 31, 2025 @02:23AM (#42885375)
I feel this article misses the point in many cases. Take, for example, error handling. It's labourious in Go, but that's not the only issue. I'm not going to go into all the details in this comment (others have covered this at length) but:

1. Go's error handling has four possible cases (result and no error, no result and error, result and error, no result and no error) when only two make sense.

2. A consequence of the above is that it requires null values (nil in Go)

I don't see how this can be considered good design.

Re:Go Is a Well-Designed Language by Zanfa on Friday January 31, 2025 @02:50AM (#42885495)
> 1. Go's error handling has four possible cases (result and no error, no result and error, result and error, no result and no error) when only two make sense.

A partial success, that returns both a result and an error definitely makes sense. For example, you’re streaming data over a network, receive some bytes, but get disconnected before it’s complete. It would make sense to have both the data received so far as well as the error, in order to resume.

I’m sure there’s an appropriate situation for the 4th case as well.

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.

Re:Go Is a Well-Designed Language by WolfCop on Friday January 31, 2025 @02:56AM (#42885519)
Streaming data, there was no error but also no new data available.
Re:Go Is a Well-Designed Language by guappa on Friday January 31, 2025 @07:34AM (#42887034)
That is an error :)
Re:Go Is a Well-Designed Language by guappa on Friday January 31, 2025 @07:33AM (#42887029)
Your example doesn't make sense because that's not how the syscall works.
Re:Go Is a Well-Designed Language by yencabulator on Friday January 31, 2025 @09:57AM (#42888287)
Go's Write makes a promise to not do short writes except on errors, which means it has to be a loop over write(2).
Re:Go Is a Well-Designed Language by guappa on Tuesday February 04, 2025 @02:32AM (#42929263)
Interesting. Does it return both the amount of partially written data AND the error if it fails?
Re:Go Is a Well-Designed Language by yencabulator on Tuesday February 04, 2025 @10:07AM (#42933244)
Re:Go Is a Well-Designed Language by gr3ml1n on Friday January 31, 2025 @02:50AM (#42885497)
I can think of situations where all four make sense. Not sure what you mean?

result+no error: data returned, no error happened. - Typical function call where you want some data.

no Result+error: nothing to return, error happened. - That typical call failed.

result+error: partial result, up to error. - Wrote x bytes to disk, then ran out of space.

no result+no error: nothing to return, no error. - Data for a passed query. Nothing came back, but that's not an error.

Re:Go Is a Well-Designed Language by nejsjsjsbsb on Friday January 31, 2025 @03:00AM (#42885547)
But not every situation. Make illegal state unreprestable is a good ideal.
Re:Go Is a Well-Designed Language by 9rx on Friday January 31, 2025 @02:36AM (#42885435)
> Go's error handling has four possible cases

If you consider (T, error) to be logically coupled, there is actually effectively an infinite number of cases. (T, U, error), (T, U, V, error), (T, U, V, W, error), etc. Although I suspect this take is suffering from trying to project idioms from another language onto Go.

Re:Go Is a Well-Designed Language by catlifeonmars on Friday January 31, 2025 @03:15AM (#42885618)
(T, error) is just a special case of (T, E).
Re:Go Is a Well-Designed Language by 9rx on Friday January 31, 2025 @03:37AM (#42885763)
At least we can agree it is (T, E) and not (T or E).