News for hackers. Stuff that matters.
Re:Learn Go in five minutes by simias on Tuesday January 05, 2021 @11:57AM (#25647520)
My main small day-to-day usability gripes with C are lack of type inference, lack of destructors and terrible ergonomics for error handling. Go solves two out of three, but it really dropped the ball hard on error handling which is very disappointing IMO.

Things like generics and garbage collection involve some deep tradeoffs, so I get Go's take on them, even if I don't necessarily agree with it. On the other hand IMHO Go's crappy error handling boilerplate is not something I find acceptable in a modern programming language.

Re:Learn Go in five minutes by autarch on Tuesday January 05, 2021 @12:13PM (#25647773)
I agree that the error handling is terrible, but I'm not sure how much better it could be without generics.

For me, the gold standard in error handling is Rust, where the type system simply does not allow you to ignore errors. This means that the existence of error handling is checked at compile time. Of course, this doesn't mean your error handling is _good_, but I think that's beyond any language design to enforce.

But the Rust system is entirely built around a generic Result type, where both the non-error result (an int, string, struct, etc.) _and_ the error type itself are both generic.

Re:Learn Go in five minutes by papaf on Tuesday January 05, 2021 @01:39PM (#25649146)
the type system simply does not allow you to ignore errors

Which is excellent.

the gold standard in error handling is Rust

Really? What library is in fashion this week for handling errors? I have so far used vanilla Rust, error-chain and Failure.

Seems like there is so much choice to improve the gold standard:

https://blog.yoshuawuyts.com/error-handling-survey/#librarie...

Re:Learn Go in five minutes by simias on Tuesday January 05, 2021 @01:46PM (#25649219)
Go uses compiler magic to have effectively generic collections, why not hardcode a Result type in the same fashion? It's not very elegant, but it's pragmatic and error handling is important enough that it may well warrant it.
Re:Learn Go in five minutes by autarch on Tuesday January 05, 2021 @05:34PM (#25652159)
Yeah, that's a fair point. I imagine this could be better than what's there now.
Re:Learn Go in five minutes by enw on Tuesday January 05, 2021 @12:04PM (#25647645)
How would you design the error handling?

Personally I'm glad Go has stayed out of exceptions (panics don't count), at scale it's so much easier to reason about flow.

Re:Learn Go in five minutes by bmn__ on Tuesday January 05, 2021 @12:28PM (#25648031)
Monadic error handling like in ML work-alikes, Rust etc. would be a good start. Adopt:

• https://github.com/rebeccaskinner/gofpher

• https://speakerdeck.com/rebeccaskinner/monadic-error-handlin...

I've been talking to the local Go user group. No one even knows about that concept. This continues a pattern of general ignorance/lack of looking beyond one's horizon I've noticed.

Re:Learn Go in five minutes by steve_adams_86 on Tuesday January 05, 2021 @12:07PM (#25647691)
The error handling feels deeply wrong to me too. I love the explicitness and how hard it is to ignore errors - all languages should make it so easy to expect and handle potential errors - but other features (or lack thereof) of the language make it so you can’t handle any of it in concise or sane ways. Code is plastered with the same boilerplate, everywhere, always. It makes up a significant mount of all Go code.