4 ms·
Most concise: absolutely. Most performant: never. Most understandable: yes, but only if you are cognizant of which call paths can result in an exception and whi
by ComputerGuru 7y ago
Most concise: absolutely. Most performant: never. Most understandable: yes, but only if you are cognizant of which call paths can result in an exception and which can’t (i.e. until your code base becomes too large or you’re not the one that wrote it).
- chrisseaton 7y ago> Most performant: never. I disagree. An exception can be faster than manually unwinding a set of nested scopes.
- lllr_finger 7y agoMost exceptions, at least in the JVM where this is commonly debated, will incur a penalty of building up the exception and unwinding the call stack. What aspect of performance are you using as an example?
- chrisseaton 7y agoAn exception thrown and caught within a compilation unit is effectively a goto. It can translate into nothing more than a jcc instruction, or even nothing at all if it's unconditional. This can be higher performance in practice than threading through a set of Either-style return objects.
- hopia 7y agoThrowing exceptions may be the most concise, but handling them rarely is. But most importantly, static type systems lose the ability to infer what's coming so these may turn out to be really pesky problems.