Why Go Can't Try
niketpatel.com
Why Go Can't Try
1–10 of 74 posts
Re: Why Go Can't Try
#2Re: Why Go Can't Try
#3Re: Why Go Can't Try
#4Re: Why Go Can't Try
#5Re: Why Go Can't Try
#6It's more complicated. There is no single correct way to check for errors. Some standard library functions can return data and an error: https://pkg.go.dev/io#Reader
Re: Why Go Can't Try
#7Re: Why Go Can't Try
#8... So what? From what I can tell that's all anyone has asked for in the context of something to just return nil/error up the call stack.
Re: Why Go Can't Try
#9The author doesn't touch on it, but the bigger problem with things like Foo|Bar as an actual type (rather than as a type constraint) is that every type must have a default/zero value in Go. This has proven to be a difficult problem for all of the proposals around adding sum types, whether they're used as errors or otherwise. For example, to support interface{Foo|Bar} as a reified type, you'd have to tolerate the nil…
Hot take, maybe, but this is one of the few "mistakes" I see with Go. It makes adding QoL things like you mentioned difficult, requires shoehorning pointers to allow for an unset condition, some types don't have a safe default/zero value like maps, and makes comparisons (especially generic) overly complex.
Re: Why Go Can't Try
#10"Here's the uncomfortable truth: a try keyword in Go without fixing the error type is just syntax sugar. You'd get slightly less typing but none of the real benefits - no exhaustiveness checking, no compiler-inferred error sets, no guarantee that you've actually handled every case." ... So what? From what I can tell that's all anyone has asked for in the context of something to just return nil/error up the call stack…