News for hackers. Stuff that matters.
Re:The Year of C++ Successor Languages by masklinn on Monday January 02, 2023 @08:29AM (#34217606)
> Exceptions don't do that

Exceptions actually do that, except hidden and unsignaled.

> They're also much more efficient than branching and maybe returning on the result of every single function call.

Not when actually taken.

Re:The Year of C++ Successor Languages by dureuill on Tuesday January 03, 2023 @03:15AM (#34229103)
> Exceptions actually do that, except hidden and unsignaled.

Which IMO is good in exactly one situation: when raising the exception means that the program contains a bug.

Using panics (ah sorry... exceptions) in this case is justified as it should be really exceptional (if there is a bug anyway we have more pressing problems than performance) and in the absence of bug if we were to use a Result type it would mean we would have a "BugError" variant that is actually dead code everywhere where the program is not buggy.

So in my opinion a correct approach is to unwrap whenever you have an invariant that guarantees that there should be a value, with a panic handler set at the boundary of the logical task to fail the entire logical task in case there is a bug. A logical task can be an asynchronous light task, a thread, or the whole process depending on the situation.

I much prefer it not being the whole process when the process is e.g. a web server or a word processor (and the failure occurred somewhere in an ancillary function)