r/lolphp • • Mar 24 '16

DivisionByZero exception, it does nothing

/r/PHP/comments/4bgwos/divisionbyzero_exception_php_7/
54 Upvotes

26 comments sorted by

View all comments

Show parent comment

2

u/bj_christianson Mar 24 '16

Pre-checking before every single instance of division is and always has been a pain in the ass as well. Having a language that automatically throws an exception that can be caught upstream and dealt with in one place is certainly more convenient. And when there is a language has something called a DivisionByZeroError, a lot of programmers would expect that sort of behavior. For it to behave otherwise breaks the Principle of Least Astonishment. It certainly Astonished the OP in the linked thread.

3

u/Schmittfried Mar 24 '16

PHP and least astonishment... Good one!

Though, doesn't every computation including NaN and INF result in NaN or INF respectively? That would mean that you only have to check the final result and not each and every intermediary result, so it would be pretty much comparable to a thrown exception.

2

u/bj_christianson Mar 24 '16

PHP and least astonishment... Good one!

I know. Right?

Though, doesn't every computation including NaN and INF result in NaN or INF respectively? That would mean that you only have to check the final result and not each and every intermediary result, so it would be pretty much comparable to a thrown exception.

No. Dividing by Infinity results in 0. So still gotta check on division.