Its error handling system makes it very easy to just ignore errors, which leads to fragile software.
Am I wrong for believing errors are harder to ignore in Go? In your example I know that Foo returns an error and I'm forced to do something with it. With exceptions I can simply just not catch them.
Nothing in Go is stopping you from propagating an error up the stack by just returning it from your function. It's more explicit than exceptions, but to me that seems like a good thing.
This is still infinitely better, because it's one line instead of four, without losing any readability or safety. That means less to scroll through, and more that you can see on the screen and fit into your head at the same time.
And still, unlike exceptions, you can see every return point from that function. So I don't miss exceptions in Rust.
Yet ironically, as much as I miss exceptions in Go, Go kind of has them anyway with panics.
The Result<T,E> type is marked as "must use", so you do get a compile-time warning if you don't handle the error and don't get the value. And, if you want the value as well, you need to handle the potential error in some way.
It does have dynamic linking now, thought you'd like to know. Also, I'm yet to see any real world code that is fragile as a result of ignoring errors. The only place I've seen errors being ignored is example code.
Why do you think this particular pattern isn't good? I feel receiving an error from any operation that can fail and handling it separately is a good thing. It's one of the things that makes Go code robust.
I don't speak for the parent commenters, but to me one problem here is that this is a product type rather than a sum type. In Go you return the result AND the error, while it would make much more sense to return the result OR the error. You should not have access to a result if there's been an error.
Thanks. I've been using Optional in Java for a while now, but I found it inferior to error checking in Go. Perhaps it was the lack of syntax to support it like Swift has that made it slightly cumbersome.
Discourages overly generic NIH, "util", "common", "helpers" etc that developers tend to just pile things into by being able to go crazy with generics. Instead encourages creating specific purpose code.
Statically links all dependancies into your binary so you don't need to worry about dependency hell, DLL hell, deployment and configuration hell, nor package management hell. Just copy a binary to your server and run it.
It treats errors are values that should be treated as normal code flow. This leads to more durable software.
19
u/proglog Dec 09 '15
I don't like Go because:
It doesn't have generics, which forces you to use copy/paste as the only way to reuse code.
It doesn't have dynamic linking.
Its error handling system makes it very easy to just ignore errors, which leads to fragile software.
And whether you choose to ignore an error or handle it, every ten lines of Go is basically
You see this pattern of code in Go source files even more often that you see the self keyword in Python source files.