3 ms·
I really want to like Go, but I can't stand looking at Go code. The error handling is such a turn off.
by Fervicus 1mo ago
I really want to like Go, but I can't stand looking at Go code. The error handling is such a turn off.
- vrosas 1mo agoWhy would you say something so controversial yet so brave?
- kajika91 1mo agoNot that I like go at all but because of it my C++ is starting to look like it as I am returning tuples of [result, error]. I try to avoid exceptions, is there any better ways? (Variant looks a bit more complicated but could be a totally OK alternative)
- ameliaquining 1mo agoC++23 introduces std::expected, which is a simpler alternative to std::variant designed specifically for the result-or-error use case. You still don't get pattern matching, but Go-style tuples don't give you that either.
- whalesalad 1mo agoPersonally I feel go has many issues and is ugly as hell but the error handling is really the least of my worries.
- Fervicus 1mo agoIt's the ugly as hell part that gets me.
- JyB 1mo agoPretty childish. People have no trouble looking past it when they care about actually shipping reliable software that properly handles all code paths. Including error paths that are ignored in so many codebases.
- Fervicus 1mo agoI don't think it's childish to dislike verbosity in a language. Readability is important. There is a reason why there are so many programming languages that compile to Go: https://github.com/ubavic/compiles-to-go https://github.com/ubavic/compiles-to-go
- preisschild 1mo agoits simple and it works
- Arbortheus 1mo agoThis was my original take when I learned the language, but I later realised “errors as values” is one of the strengths of the language. I have run both Go and Python backends in production for years. There is an entire class of bugs present in Python services (missing error handling) that simply does not happen in my Go services. Python puts the burden of knowing what exception types a function call will raise on the caller, in Go I just check for err. Even if I do not anticipate every failure mode the Go call will raise, I will always log the error and handle it in a controlled manner. I couldn’t count the number of times I’ve encountered an unhandled exception in my Python code, and often in such a case the logging will be lacklustre because you will just see a huge stack trace, but lose the contextual logging I would have automatically added in Go. Perhaps a syntactic sugar is in order to reduce verbosity.
- Fervicus 1mo agoI don't have a problem with the error handling per say, but it's the verbosity, yes.
- qwm 1mo agoSome languages do it better, but it's really not a problem. It's just verbose, but people say that about Java and that never stopped it from being used everywhere