3 ms·
Any programmer in almost any language who mixes types like that without understanding the implicit type conversion semantics is asking for trouble. Implicit ty
by Pitarou 13y 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?
- lmm 13y agoJavascript, C and Java suck, yes. Show me something as bad as the OP in python3 and then maybe you'll have a point.
- Pitarou 13y agoEven 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.