3 ms·
I tend to agree with you, not for the different semantic aspect, since they both are capable of expressing the same thing (with checked exceptions), but for the
by erustemi 2y ago
I tend to agree with you, not for the different semantic aspect, since they both are capable of expressing the same thing (with checked exceptions),
but for the performance impact of exceptions. If I'm not mistaken throwing an exception has a much larger cost than a simple return due to needing to construct the stacktrace.
So using exceptions for an expected path of a function seems sub-optimal.
- lolinder 2y agoGenerally speaking the Left (error) value of a Result is unexpected during normal operation. You "expect" it in that you prepared for a specific kind of failure but you won't generally see a whole bunch of Left values in a hot loop unless something has gone horribly wrong, in which case performance is not your primary concern. Meanwhile, one of the biggest weaknesses of Result types is precisely that they don't carry a stack trace with them, which can make it hard to debug a failure when one occurs. Libraries like anyhow in Rust [0] actually go out of their way to retrofit Error types with stack traces because it turns out that most of the time we actually want them. [0] https://docs.rs/anyhow/latest/anyhow/ https://docs.rs/anyhow/latest/anyhow/