2 ms·
With an exception (not checked exceptions) you get the advantage of the compiler knows about this and can optimize some code paths - any function that doesn't h
by bluGill 2y ago
With an exception (not checked exceptions) you get the advantage of the compiler knows about this and can optimize some code paths - any function that doesn't handle the function or have clean up to do can be bypassed, while result/checked exceptions need to go into that function anyway - which may be faster, more benchmarks needed. (though is possible a "sufficiently smart" compiler could understand thus pattern and turn it into an exception).
So the real question is syntax - which do you prefer: having to write some result type all over instead of the regular return type you mean, or knowing that "magically" at unpredictable times your function will just abort in the middle. There are pros and cons to both, so anyone arguing absolutely for either side is wrong - at least now when we don't have decades of experience with result in large projects (though maybe we do in a single project)
- gpderetta 2y ago> With an exception (not checked exceptions) you get the advantage of the compiler knows about this and can optimize some code paths while result/checked exceptions need to go into that function anyway. Once you convert them in CPS form there is really no difference between the two. In principle you could compile both to exactly the same code. [edit: also not sure why are you singling out checked exceptions] [edit: specifically you could compile any code that returns an Either to a function that takes two return continuations instead of just one, and in CPS form exception-like non-local exits are trivial] Of course in practice traditional procedural languages do not compile through CPS and use abnormal edges in basic blocks to represent exceptions. > There are pros and cons to both, so anyone arguing absolutely for either side is wrong I'm in the camp that, in a well designed language[1], there would be no difference between the two :D [1] according to my personal preferences that I can assure you are completely objective!