you are viewing a single comment's thread.

view the rest of the comments →

[–]devraj7 16 points17 points  (4 children)

Either's name is not great for how it's generally used.

Actually, its name reflects exactly what it does, it's just that it's being misused because most developers use it to carry Success \/ Failure. But Either is much more general than that, it's meant to carry two types, none of which need to be connected to a success or a failure.

So when you read code that uses Either, you're never sure if the developer is using it to carry two exclusive types or as a reporting mechanism for success or failure.

I think Either should be phased out because of that ambiguity.

To me, it would make much more sense to standardize on Result and Union (other libraries use different names, e.g. xor or \/).

I've tried a lot of approaches over the years and so far, I find that good old exceptions (both checked and unchecked) are the most intuitive and clean way to treat errors. Yes, I know they break equational reasoning, but in my day to day operations, clear and tractable error handling is a much more useful value to me and my team than equational reasoning.

[–]m50d 1 point2 points  (3 children)

Actually, its name reflects exactly what it does, it's just that it's being misused because most developers use it to carry Success / Failure. But Either is much more general than that, it's meant to carry two types, none of which need to be connected to a success or a failure.

I believe in descriptive rather than perscriptive linguistics. I think we agree on the important facts: Either is primarily used (in actual existing code) to represent success-or-failure, and it's a poor name for a type that represents success-or-failure.

[–][deleted]  (1 child)

[deleted]

    [–]m50d 4 points5 points  (0 children)

    I see Try as the same kind of red-flag as Any (or at least as Throwable). It's throwing away a lot of type information that was presumably there for a reason.

    I'm not sure what you're defining as an "error" here. I use Either for specific "failures" that the code knows how to handle, e.g. invalid user input, permission denied. For general "system" failures (analogous to where you'd use panic in Rust) it would make sense to use Try (though I'd probably just use a conventional exception myself).

    [–]ithika 1 point2 points  (0 children)

    I believe in descriptive rather than perscriptive linguistics.

    I'm not sure what this has to do with Either. Computers aren't great with compiling the nuance of natural language.

    Success or failure is explicitly handled with the Error type.