3 ms·
Except that error returns such as Either have their own problems. What is the main complaint about checked exceptions in Java? Yes, handle or _declare_ them in
by zvrba 5y ago
Except that error returns such as Either have their own problems. What is the main complaint about checked exceptions in Java? Yes, handle or _declare_ them in method signatures: adding a checked exception to a previously non-throwing method breaks all callers. What happens when a previously non-erroring function must be changed to be able to report some error? Yes, the same: change the signature to return Either and fix all callers.
And then what about conditions like division by zero, or arithmetic overflow? Are arithmetic _operators_ supposed to return Either/Option instead? Or just crash the program? Which may be a long-running server and only one request of many got corrupt?
While not very ergonomic, I still prefer exceptions way more than return values. Ergonomics could be fixed by tooling; hopefully that will improve if developers start to demand it.
Finally, even functional languages such as SML and Ocaml have exceptions where they are also even recommended for control flow such as breaking out of deep recursion.
- rualca 5y ago> And then what about (...) If seems you've missed the whole point of suggesting the use of Either/Result monads. It's entirely irrelevant if you have legacy code that does not support returning error codes a certain way. The whole point of Either/Result monads , specially regarding exceptions, is that they provide a clean way to handle errors (and not exceptions) in the normal code path by explicitly making them a part of a function's codomain, and without relying on magic bubbling up. And no, Either/Result monads are only designed to handle expected results, not exceptional behavior. Perhaps your main source of confusion is conflating exceptions with an error condition. In that case, think of Either/Result monads as "I made a HTTP request and the response was a 200 or a 500 status, thus the code path follows accordingly" and exceptions as "I made a HTTP request and I got an OutOfMemoryException".
- aidos 5y agoI just looked into this following someone else recommending Either and my knee jerk reaction is the same as yours. The nice thing about exceptions is that you get to take a large block of code and treat it as a whole fail-able unit. In terms of a control flow structure, being able to raise deep and goto nearer the top of the stack removes large amounts of boilerplate code, which, in my experience, makes the code more readable. I use exceptions sparingly and deliberately. And when used like that, I find them to be a helpful feature that improves the codebase.
- tayo42 5y agoWhy cant you do what haskell does? Or you can still use exceptions alongside either and options. I think the problem with python is they get used for everything.