3 ms·
There are some was to make error handling much less annoying in go. Since error is just an interface it's pretty easy to make monadic constructs that can carry
by rebeccaskinner 10y ago
There are some was to make error handling much less annoying in go. Since error is just an interface it's pretty easy to make monadic constructs that can carry the error information and let you write pipelined code. IMHO it makes the code much cleaner and easier to read, but a lot of golang enthusiasts haven't really adopted the idea because it's quite different from the established idioms around error handling. Hard-core gophers love them some verbose and stupidly explicit code; but I'm hoping that as the language gets adoption in the wider community the voice of reason will win here.
- the_duke 10y agoInterfaces require casting and hurt performance, though. You could come up with `Either` types, but due to the lack of generic structs you'd have to have a whole lot of those. Interestingly, Rust has basically the same error handling idiom, but verbosity is considerably reduced by the '?' operator (previously the try! macro). When I was coding in Go, i would have loved that feature. The mind-numbing error checking in go is hugely annoying.
- tokenizerrr 10y ago> When I was coding in Go, i would have loved that feature. The mind-numbing error checking in go is hugely annoying. Ugh. Yes. I really want to love go. No, I really love go. But this is so annoying.
- woah 10y agoCould you link to some instructions?
- rebeccaskinner 10y agoI've been working on putting together an in-depth series of blog posts about it. I'm presenting on the topic of better error handing in go at the Agile Tech Conference this year, and I'd like to start getting everything in order soon- I'll probably post here on HN. In the short term I have a really rudimentary library I've put up here: https://github.com/asteris-llc/gofpher https://github.com/asteris-llc/gofpher and a presentation on it here https://github.com/rebeccaskinner/presentations/tree/master/golang_monads https://github.com/rebeccaskinner/presentations/tree/master/... (should build with pdflatex, I need to get an actual pdf built soon) Rob Pike has a blog post that looks at a similar, although ideologically different, approach to doing it: https://blog.golang.org/errors-are-values https://blog.golang.org/errors-are-values I think the latter is more go-ish, although also less generic than the monadic approach- it's also more in keeping with the ideology of go, but in practice I still never see it being used much in production code.