(no subject)
Mar. 25th, 2011 10:30 pmA collection of mini-rants today, from a couple of hours spent hacking together a bit of PHP:
- Which numpty decided that the default behaviour of a switch statement should be to fall through. It's almost never what you want!
- In the same theme, which numpty decided to make assignment and equality use different operators, to make assignment single-equals, and to not have any kind of warning if you use single-equals in an if statement.
- Why does PHP not have a usable variable type for dates? Even classic VB has one!
no subject
Date: 2011-03-26 01:07 pm (UTC)Those behaviors are the only ones that seem likely to me. Doing anything else (especially in PHP, which doesn't really have a compile stage at which to issue sane warnings) would make me react the reverse of how you did: "What do you *mean* switch doesn't fall through?"
Aren't they both just carryovers from C?
no subject
Date: 2011-03-26 08:53 pm (UTC)This rant mainly appeared because the first two were the source of many bugs in a bit of PHP I was hacking together last night. A language that didn't have that behaviour, or a good IDE (presumably such exist for PHP, but I've only found not-completely-bad ones) that'll flag up such things would have prevented all of those bugs.
As for the third thing, because PHP is really a C compiler in disguise it uses the C library convention for dates. Even better, the documentation for strftime states "Not all conversion specifiers may be supported by your C library, in which case they will not be supported by PHP's strftime()" but doesn't say which if any conversion specifiers will be supported. Admitedly they did add a DateTime object in PHP 5.2, but it took until PHP 5.3 for it to actually be possible to compare DateTime objects.
no subject
Date: 2011-03-26 11:26 pm (UTC)I guess I've never worked in a language that wasn't derived from C syntax in that way, so again, I would find it surprising that something like PHP -- which clearly shows its roots as a C-style syntax -- didn't behave like C did. It can be frustrating switching from another paradigm, certainly, but I don't think PHP is to blame there, just happens to be where you got bit :)
no subject
Date: 2011-03-26 11:39 pm (UTC)While VB6 doesn't have a datetime object, it does have a native Date type and a bunch of functions for manipulating them. It's not perfect, but you can use comparision operators on a pair of Dates (or, for that matter, on a Date and anything else that looks sufficiently Date-like as VB does automatic type coercion) and have it just work. It's one of the few things where I think VB got it right. Another is in treating Strings as native data types, rather than as byte arrays (the C way) or glorified objects (the Java way).