6 ms·
I think the semantics of Go's error handling is pretty good, but the syntax could use work.
by piinbinary 9y ago
I think the semantics of Go's error handling is pretty good, but the syntax could use work.
- knodi 9y agoYa my number 1 request for Go2, better syntax for error handling.
- dguaraglia 9y agoSomething as simple as allowing the use of multi-result calls in if statements would make a huge difference. Being able to write "if err := blah(); err != nil { ... }" is great (although it does kind of hide the original call.)
- seanpfeifer 9y agoThis is possible in Go right now. Use "if thing, err := blah(); err != nil { ... }". This is common for things like map access. See an example here https://play.golang.org/p/P3k5tgFLd2 https://play.golang.org/p/P3k5tgFLd2
- dguaraglia 9y agoWait! Is this a go 1.9 thing? I've been using 1.83 all this time.
- zimpenfish 9y agoI don't think it's a 1.9 thing - I've got code from 2017-02 which uses it (the quickest example I could find in my repos)
- dguaraglia 9y agoWTF? You are absolutely right. I could've sworn I had issues with this before. 25% of my irritation with Go just evaporated (the other 75% is how hard it is to run Delve, but I'll figure that out.)
- ngrilly 9y agoThis has been possible for years ;-)
- ngrilly 9y agoThere is an ongoing reflexion on making error handling less verbose, but as you can see in the link below, there are tradeoffs, as always: https://github.com/golang/go/issues/21161 https://github.com/golang/go/issues/21161