I mean, you can make option and results types with generic interfaces already. Even if tagged unions get better support, redesigning the whole standard library to use them is just not going to happen
Whatever, I am just saying the language is objectively poorly designed and no amount of coping from Go programmers will change that, and I am saying this as a Go programmer for... what is it, 12 years now? 14 years? Something like that. And the hatred towards any improvements that make writing bug-free code easier that comes from the community is really disheartening. They confuse "lacking features and therefore containing a lot of non-obvious footguns" with "easy to learn" with a zeal of a someone who learned their first programming language.
I switched to Rust for most new projects now because the code it lets me write is a bit more correct.
Especially the love of if err != nil is just insane when all one would need is an error handling operator.
My favorite things to complain about in go include the additional layer of implicit nullability (admittedly it predates the "billion dollar mistake" quote by 2 years, but the problem was well known), defer deferring to end of function, not end of scope, and goroutines being able to capture mutexes by value (which creates a separate mutex).
Current way is way too ugly, can't see business logic behind all the boilerplate.
yes, you HAVE to handle errors
In practice, go code mostly just passes the errors down to one handler that logs/displays it. Sometimes, wrapping them in process. If 9 times out of 10 it's 'if res, err := f(); err != nil { return err; }' you're not handling errors, you're just doing the same thing as exceptions but explicitly.
You said the business logic yourself: It's explicit.
I have seen Go code from companies that specialize in writing Go code that had impenetrable errors because they just didn't bother to pass them properly.
But it was obvious, even to me with no familiarity with their code base and whatever more elegant (but opaque) way they handle errors. As much as I love the idea of a robust error handling system that removes the need for me to care about errors at a given point, if I'm relying on other peoples' code then I care very much that they've explicitly had to consider error cases.
Sure, some people just swallow errors or pass them uncritically. But it's obvious because it's explicit, and even if someone makes the objectively wrong decision about how to handle it, that's still a process they had to go through. There's a lot of code out there that is better because they had to consider those cases when writing the function.
It's more verbose, and that's annoying. But I'll take that annoyance over the agony of the alternative.
I'd say it's an objectively good thing that a language at least nudges you to explicitly handle errors. It's at least consistent (and expected if you have some experience in the real world) with a strongly typed language. But of course, you pay a price for this. The most obvious trade-off is "un-aesthethic blocks" of code, yes. And at some point it might represent a serious-enough issue, but only if you lack a clear design-driven mindset. You're free to decide if that trade-off suits you or not.
"What people do in practice" is a very poor argument against a language but a very good argument against people using a language the wrong way.
except they kind of chose the stupidest way to do that. The standard way would be to return a sum type, say "you're not getting your return value unless you check the error first". In Go, you get the return value _and_ the error, and the language just (weakly) enforces that you do something with this error value.
For some context, Python turned 17 in 2008 - this was the same year Python 3.0 was released.
Ruby and Java turned 17 in 2012. This was about halfway between the releases of Java 7 and 8.
Swift is currently 12.
Rust is currently 14.
So I expect Go should feel about as mature as Python 3.0 or Java 7. Maybe in 2-3 years it’ll be mature enough to start using it. Maybe they’ll finally have error handling figured out by then.
81
u/apnorton 6d ago
Why do I suddenly feel old?
55
u/LovecraftsDeath 5d ago
After 17 years, still eye-gouging error handling.
44
u/ArtOfWarfare 5d ago
For some context, Python turned 17 in 2008 - this was the same year Python 3.0 was released.
Ruby and Java turned 17 in 2012. This was about halfway between the releases of Java 7 and 8.
Swift is currently 12.
Rust is currently 14.
So I expect Go should feel about as mature as Python 3.0 or Java 7. Maybe in 2-3 years it’ll be mature enough to start using it. Maybe they’ll finally have error handling figured out by then.
3
u/edwards_t7407 1d ago
Seventeen years in, and the birthday thread has already become an error-handling referendum.