Hacker News new | past | comments | ask | show | jobs | submit login

Sure it is:

To avoid implicit type coercion, use the identity operators === and !==.

Of course, the code you posted doesn't parse without adding parens. And when you do, it becomes much more obvious what it's doing and why.




Sorry, I meant that as a bunch of compares that are mutually inconsistent, not one big expression. And "don't use ==" isn't really a solution until you persuade the runtime and every major library author to stop using it.


I don't get your point. Nobody has said "don't use equality." Equality is the right choice nearly all the time.

I've worked on some very large web apps (mostly C#, Python and PHP) and I can't recall ever really being foiled by php's implicit casting.

Just out of genuine curiousity, can you share an example where this caused a problem that you had to debug?

And if php implicit casting did somehow cause you problems, surely it was fixed by changing it from equality to identity?

So in summary... this could potentially cause a bug, but probably not, and if it does, it would be a consistent bug, and it would be fixed by a single keystroke.

Why, again, are we talking about this?




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

Search: