5 ms·
Feel free to enlighten us specifically about how they are better.
by 4ydx 12y ago
Feel free to enlighten us specifically about how they are better.
- frou_dh 12y agoIn Go, you're not returning a sum type, so it's down to the programmer to remember that the "real" return value is likely toxic waste when its copassenger the error return value is non-nil.
- Karunamon 12y agoWhat'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.
- jbooth 12y agoWait, that's it? The difference between bad (with italics!) and awesome is being able to reference the garbage half of a multiple return?
- frou_dh 12y agoI'm not the GP. Ask them for their full story.
- wting 12y agoYou can embed metadata with sum types on a return object. You can then use the metadata programmatically to increase correctness, enhance readability, and reduce boilerplate. This blog post goes into more details: http://fsharpforfunandprofit.com/posts/recipe-part2/#series-toc http://fsharpforfunandprofit.com/posts/recipe-part2/#series-...
- 4ydx 12y agoOk thanks for filling in the blank.
- howeman 12y ago> You're not returning a sum type so it's down to convention to remember that the "real" return value is effectively garbage when the error return value is non-nil. There are many cases where this is not true.