3 ms·
> 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 la
by 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.