Hacker News new | ask | show | jobs
by herval 1425 days ago
1 and 2 are now possible to implement, since 1.18 - I'm using this and it does save quite a bit of boilerplate: github.com/life4/genesis

I'd love to see less verbose error handling too, but Rust's ? IMHO is not the best way to go - it adds quite a bit of magic and makes debugging difficult, when a question mark at the end of a line "injects" an unexpected return statement.

3 comments

2 has been possible since version 1.0

https://go.dev/doc/effective_go#maps

While it won't win the hearts of Gophers, I would use a utility function that panics if error, at least on throw away code.
There are some instances of it in the stdlib, e.g. <https://pkg.go.dev/html/template@go1.18.4#Must>

I'd guess with generics we can expect a generic "Must" to replace them.