Re:PHP cheat: ==, ===, empty(),is_null(),isSet()
by wvenable on Monday August 25, 2008 @09:01PM
(#286626)
The fact is, if you look at it in this abstract way then your feelings are valid. But during concrete web development, the functionality of PHP's comparison operators make a lot of sense and make the code simpler and easier to understand.
[ Parent
| on HN ]
Re:PHP cheat: ==, ===, empty(),is_null(),isSet()
by time_management on Monday August 25, 2008 @09:21PM
(#286646)
Why is this? I'm not sure I understand where the gain is.
I guess that, for me, the cost of a few keystrokes involved in writing "if x == 0 then ..." vs. "if x then ..." never seemed to be worth the hassle of remembering false values. I've always found it preferable to make the comparison being made explicit.
I also generally dislike the practice of using reserved values to signify empty data, e.g. 0 for missing numerical data. I prefer to use ML-style option types, e.g. None vs. Some 0, and in a dynamically typed language, I'd just use the nil/().
Re:PHP cheat: ==, ===, empty(),is_null(),isSet()
by wvenable on Monday August 25, 2008 @09:31PM
(#286655)
On the web, all the data comes in as strings including numbers. So the comparisons work well the numbers in strings. The rest of the weirdness comes from PHP copying C and Perl semantics.
Re:PHP cheat: ==, ===, empty(),is_null(),isSet()
by cosmo7 on Tuesday August 26, 2008 @12:14AM
(#286755)
Don't blame C. This is usually the point that programmers realize why statically typed languages are such a good idea.
Re:PHP cheat: ==, ===, empty(),is_null(),isSet()
by time_management on Tuesday August 26, 2008 @09:39AM
(#287049)
When I moved from Java to Python, I was sure that dynamic typing was the way to go, because the type system in the C/Java family is such a hindrance, while lacking the power of a mature type system as seen in ML or Haskell. When I moved from Python to ML, I was equally adamant about static typing being the way to go, because the ML type system is pretty awesome in terms of compile-time error-checking and documentation. Now that I'm learning Lisp, I'm open to the benefits of dynamic typing, or at least want to keep an open mind about the matter.
Re:PHP cheat: ==, ===, empty(),is_null(),isSet()
by time_management on Monday August 25, 2008 @09:49PM
(#286665)
This makes sense. I guess a programmer who does a string => bool type conversion desires different behavior than one who does string => int => bool, so the fact that they produce different results ("foo" => true vs. "foo" => 0 => false) is part of the design.