6 ms·
> You can ignore the error case on a result / the None case on an option as easily as you ignore the `err` today. The point of a result type is that you _canno
by MHordecki 6y ago
> You can ignore the error case on a result / the None case on an option as easily as you ignore the `err` today.
The point of a result type is that you _cannot_ ignore the None case. Any method that would provide you with the value will also check that the error is not present.
In comparison, you can happily ignore `err` in Golang and continue with an invalid `value`.
- weberc2 6y ago> In comparison, you can happily ignore `err` in Golang and continue with an invalid `value`. I'm struggling to envision a Result type that requires you to be more explicit than `foo, _ := fallible()`. Seems like `fallible().Ok()` and similar are strictly less explicit.
- hombre_fatal 6y agoTo do anything with a Result/Optional, you have to explicitly get the value inside the box at some point. But the container abstraction also gives you a nice composition abstractions instead of the uncomposable top-level `val, err := do()` destructure. Though perhaps not quite as compelling without real sum types. I'd have to play with Go's generic-typing sandbox more to form a stronger opinion.
- deleted 6y ago[deleted]
- peter_l_downs 6y agoI see what you're saying, and while I think you're right, I think a lot more of the value is in being able to use `Map()` /`FlatMap()` to be able to avoid thinking about error checking at all, as I laid out in the second part of this comment https://news.ycombinator.com/item?id=23549396 https://news.ycombinator.com/item?id=23549396 . The convention of returning `(value, err)` goes a long way towards enforcing the checking of errors; I have golangci-lint's `errcheck` linter enabled and basically cannot accidentally ignore the `err` values. In any case, Option/Result types are extremely useful and I'm happy that with generics the language will be able to include them!
- estebank 6y agoFor an ergonomic implementation of Result and Option you need to be able to represent tagged unions/enums/sum types, and having pattern matching makes dealing with them much more natural. These features are not planned for Go (yet?), right?