5 ms·
If you use it for error handling, it takes a lot of mental energy to remember which side is the happy path and which side is the error path. Maybe (no pun inten
by jupp0r 7y ago
If you use it for error handling, it takes a lot of mental energy to remember which side is the happy path and which side is the error path. Maybe (no pun intended), people should have used Either to build a Result type, but as it stands, raw Either is used everywhere by convention, creating confusion.
- Gajurgensen 7y agoIt would be nice if there was a standard type alias for Either which explicitly labeled good/bad values. That being said, I don't think it takes that much energy to remember that the right is the good value. If you are comfortable with monads, just remember that monads must be parameterized over a single type, and for Either that will be the right type (because we must partially apply the type constructor with the left type to get it down to the correct form).
- seppel 7y ago> That being said, I don't think it takes that much energy to remember that the right is the good value. And then clever guys come and use left as the good value, because then want to retry on error (as you can see in this thread). Plus it takes quite some energy to discuss the, well, unfortunate naming.
- leshow 7y agoI'm not sure which definition you're referring to, but every one I've seen you'd be hard-pressed to use left as the 'good' value. The type's definition favours 'right' for Functor/Applicative/Monad/etc instances.
- seppel 7y agoI'm referring to this comment: https://news.ycombinator.com/item?id=20224097 https://news.ycombinator.com/item?id=20224097
- leshow 7y agoThere are zero implementations of Left being the Ok value, just this hypothetical put forward by another commenter. edit: I should specify that I mean when Either is used as a 'Result' type. There are plenty of other use cases you can use Either outside of Ok/Err values.
- leshow 7y agoRight is a synonym for 'correct'. How much mental energy does that take?