3 ms·
that's a lot of characters added for essentially the same result - exceptions were introduced because bubbling things up explicitely is a pain !
by jcelerier 6y ago
that's a lot of characters added for essentially the same result - exceptions were introduced because bubbling things up explicitely is a pain !
- masklinn 6y ago> that's a lot of characters added Not really. > for essentially the same result With the huge differences that 1. it signals that things can fail, which largely doesn't exist with unchecked exceptions unless you re-add that information which is going to lead to similar amounts of "characters added" (e.g. “throws”) 2. you're explicitly opting into the costs and information-discarding effects, which is rather important for the language's purported goals, it supports that use-case without discarding its other important use-cases > exceptions were introduced because bubbling things up explicitely is a pain ! Not really either, exceptions were introduced to structure error handling rather than use ad-hoc and generally in-band methods, or unrestricted jumps. They also provided a very useful hook point to provide contextual information (by default or otherwise) which the aforementioned ad-hoc methods didn't account for e.g. not much contextual data you can bundle in a shell or C error code. Leveraging sum types for error handling is an oddly recent development, both because most languages don't have sum types, and because that it could be used thus doesn't seem like a very old realisation at large (just look at error handling in Haskell).
- saurik 6y agoThat structuring is important though, and is what Haskell does with monads and C++ does with exceptions (which are in many ways a kind of hardcoded syntax for an error monad). Rust just has unstructured manual error checking and propagation with some conventions to make it more likely to be sane, as it rejected both exceptions and monads as approaches to real structured error management.
- masklinn 6y agoNo, Rust has structured error checking, in fact is specifically has monadic error management, just without the monad abstraction itself.
- thinkharderdev 6y agoIt certainly can be a pain in some languages but modern functional languages (Scala and Haskell come to mind) it is actually really easy and clean. I would really not want to use the Either[Error,Result] pattern in Java but that is more a limitation of the Java language than the basic pattern
- saurik 6y agoHaskell has monads, which allow you to define the propagation behavior of Either and then hide the syntax overhead behind do notation. Using the data type of Haskell error handling--which exists in an ecosystem of monads... a way of defining the interaction of sequential code and injecting behaviors such as error propagation--but without the engine for Haskell's error handling misses the point of what functional languages are doing with errors.