Hacker News new | past | comments | ask | show | jobs | submit login

I think the semantics of Go's error handling is pretty good, but the syntax could use work.



Ya my number 1 request for Go2, better syntax for error handling.


There 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


Something 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.)


This 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


Wait! Is this a go 1.9 thing? I've been using 1.83 all this time.


I 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)


WTF? 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.)


This has been possible for years ;-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: