Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nothing wrong with automatic coercion, as long as the rules are sane.

In ruby, everything except false and nil is true. Easy.

Unless you override the == method of course. With great power...



PHP's rules, like Perl, does what the programmer wants a high fraction of the time. Except when they don't.

For instance, 0 == false isn't too crazy, it's like C. But automatic coercion of string values to ints makes "0" == false which is sometimes what you want and sometimes not.

Practically this burns people in form validation code because often you want to test if a field is an empty string and if you do the obvious thing you can end up kicking out "0".

When I write PHP I have my own "PHP on nails" library that has functions that smooth out most of the things that are wrong with the language, and one of them is a comparison operator that is somewhere between "==" and "===" that most frequently does what you want it to do.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: