Hacker News new | ask | show | jobs
by Pitarou 4641 days ago
Any programmer in almost any language who mixes types like that without understanding the implicit type conversion semantics is asking for trouble.

Implicit type conversion is evil, and I don't see how PHP's sin of favouring string -> number over number -> string is any worse than, say:

    // Javascript
    console.log(+(+!![]+(+[]+[]))); // outputs the number 10
Or:

    // C, Java

    float celsius, fahrenheit1, fahrenheit2;
    celsius = 100;

    fahrenheit1 = celsius * 9 / 5 + 32;
    fahrenheit2 = 9 / 5 * celsius + 32;

    assert(fahrenheit1 == 212); // OK
    assert(fahrenheit2 == 212); // Oops!  It's 132.  What happened?
1 comments

Javascript, C and Java suck, yes. Show me something as bad as the OP in python3 and then maybe you'll have a point.
Even if Python 3's type conversion semantics has no dark corners, I still have a point.

harshreality argued that, because PHP's implicit type conversion leads to weird behaviour, "PHP doesn't work. End of story."

In that case, nearly every widely used language (with the possible exception of Python 3) "doesn't work. End of story." That's not a very interesting or useful story to tell.

Javascript, C and Java all "don't work", at least to the extent that I would never take a job writing them.
Well, you're consistent.

As I said earlier, I agree that implicit type-conversion is evil. But if I refused to use flawed tools...