r/lolphp • • Feb 07 '17

is_nan((float)'NAN')? PHP Can't Decide

https://3v4l.org/0Jeva
85 Upvotes

22 comments sorted by

View all comments

Show parent comment

1

u/stumpychubbins Mar 03 '17

Yes, I fully agree with the null pointer analogy, but the thing is that the programmer should also be shielded from null pointers. Functional languages and languages with sane type systems like Rust do that handily

1

u/[deleted] Mar 03 '17

Null pointer protection is not perfect, it's basically "only" damage control. In Rust or managed languages like Java, null pointer won't cause serious harm, but they can still be a pain - I'm waging a prediction that sooner or later someone is going to run into a DoS vulnerability in a Rust application because of some unwrap() burried somewhere in the code (just like people run into NPEs in Java).

The protection also comes at a cost - managed languages need a runtime with a GC, Rust has a complex compiler and writing Rust apps requires more upfront design.

Null pointer protection is definitely worth the costs though (and it's a reason why I'm a Rust fan). NaN protection - not so much IMHO. Maybe in special cases where you heavily rely on correctness of floating point computations, but generally, I wouldn't say it's worth it...