4 ms·
What's the practical problem of this, though? The (varname, err := thing) pattern is sprinkled all throughout the language, enough to where it should be instinc
by Karunamon 12y ago
What's the practical problem of this, though? The (varname, err := thing) pattern is sprinkled all throughout the language, enough to where it should be instinctive for a coder to check the err value when doing anything that could fail.
- frou_dh 12y agoOf course we can put up with anything. The topic of the subthread is that it's halfassed and has a better alternative.
- jshen 12y agoA major hit to readability. Every call site where you want to check for an error requires adding another level of nesting.
- frou_dh 12y agoThat's a different issue. Pattern-matching a sum-type value, though safer, would be "noise" too.
- jshen 12y agoCorrect me if I'm wrong, but I believe with sum types you can chain together multiple calls then pattern match once at the end. In Go you have to check at each call.
- burntsushi 12y agoIf you have an unusual amount of error handling cluttering up your code in Go, then you can use `panic` (with `defer` and `recover` to convert panics to errors in the public interface).
- iopq 12y agoI've been programming without if statements. It feels a lot better using pattern matching instead of if statements.