[nycphp-talk] Why do "cool kids" choose PHP to build websites instead of Java
John Campbell
jcampbell1 at gmail.com
Thu Jan 3 11:15:48 EST 2008
Rusty has a perfectly valid point, but comparing java and php in this
regard is nonsensical because java is typed, php is not. I think a
more relevant comparison is comparing the same code in other non-typed
languages.
JAVASCRIPT:
var a = 0;
var b = "eggs";
var c = "spam";
var d = null;
var e = [];
var f = "0";
console.log( (a == b) ? "a == b\n" : "a != b\n");
console.log( (b == c) ? "b == c\n" : "b != c\n");
console.log( (a == c) ? "a == c\n" : "a != c\n");
console.log( (a == d) ? "a == d\n" : "a != d\n");
console.log( (b == d) ? "b == d\n" : "b != d\n");
console.log( (c == d) ? "c == d\n" : "c != d\n");
console.log( !!e ? "empty arrays are true \n" : "empty arrays are false \n");
console.log( (a == f) ? "a == f\n" : "a != f\n");
Result:
a != b
b != c
a != c
a != d
b != d
c != d
empty arrays are true
a == f
PYTHON:
a = 0
b = "eggs"
c = "spam"
d = None
e = []
f = "0"
print( (a == b) and "a == b" or "a != b")
print( (b == c) and "b == c" or "b != c")
print( (a == c) and "a == c" or "a != c")
print( (a == d) and "a == d" or "a != d")
print( (b == d) and "b == d" or "b != d")
print( (c == d) and "c == d" or "c != d")
print( e and "empty arrays are true" or "empty arrays are false")
print( (a == f) and "a == f" or "a != f")
Result:
a != b
b != c
a != c
a != d
b != d
c != d
empty arrays are false
a != f
Note that javascript and python fail if "d" is not defined. (PHP can
be configured to do the same if that is what you want). I won't
comment on which I think is best, but I know it sucks having to
remember the quirks of each language for something as simple as "==".
Regards,
John Campbell
More information about the talk
mailing list