News for hackers. Stuff that matters.
Re:Ewww, You Use PHP? by pilif on Friday October 22, 2010 @07:54AM (#1819316)
personally, I prefer the dynamically typed languages.

but I hate. No. HATE PHP's type conversions with its == operator.

    0 == 'foobar'
but

    true == 'foobar' && 0 == false
so

    true == false ?
eek.

Yeah. I know === exists. But if you have to compare strings and numbers, why is the default conversion method you do the lossy one? If you compare a number to a string, why can't you convert the number into a string and compare the two strings? Why convert the string into a number which will be lossy in most cases?

Re:Ewww, You Use PHP? by mgkimsal on Friday October 22, 2010 @08:03AM (#1819341)
There's == and === - they do separate things.

http://stackoverflow.com/questions/359494/javascript-vs

It's not that hard to get your head around, and at least one other major language does it this way.

Re:Ewww, You Use PHP? by perlgeek on Friday October 22, 2010 @02:13PM (#1820758)
agreed, but == being a non-associative operator is still just sick.
Re:Ewww, You Use PHP? by mjw on Saturday October 23, 2010 @12:16PM (#1823785)
I think you mean non-transitive. But yes.
Re:Ewww, You Use PHP? by invisible on Friday October 22, 2010 @11:51AM (#1820101)
Sometimes it is "easier" to just type: if (isThisReturningEmpty()) {} instead of typing: if (isThisReturningEmpty() === "") {}

And if you know something could return 0 (which is not empty), you should know to do a type-sensitive check). You are trading off HAVING to set types with HAVING to check types when needed (I think the latter is better).

Re:Ewww, You Use PHP? by Xuzz on Friday October 22, 2010 @10:15PM (#1822313)
Note that this isn't anything to do with dynamic typing: Python is very dynamic, but it doesn't have this weird coercion (or is it "automatic type conversion"?).

I hate this as well, but, I love dynamic typing. They aren't the same thing.