3 ms·
If you want to do all the work at the end, 'exceptions' do exactly that, too.
by eru 2y ago
If you want to do all the work at the end, 'exceptions' do exactly that, too.
- davorak 2y agoThrowing an exception in a function normally stops the rest of the work that function would do. That is not the case when using Inf and similar > const f = (x) => [x/2, x/0] undefined > f(10) [ 5, Infinity ]
- NBJack 2y agoI assert stopping immediately is much more practical. In many cases, you waste considerable amounts of processing power to reach a conclusion you often won't be able to use.
- eru 2y agoIt depends on your use case.
- throwawaymaths 2y agoSure but what should be the default?
- eru 2y agoRust and Haskell can solve this fairly well: both styles of dealing with errors are easily accessible. Go solves this really badly. As for specifically what to do about division: the right default depends on your application. Either way is defensible, and I would rather work on making it easy to pick either style in the language of your choice, than to worry too much about what the default should be.
- eru 2y agoThat's a good point, sometimes this is what you want.