?

Log in

No account? Create an account
A collection of mini-rants today, from a couple of hours spent… - 'Twas brillig, and the slithy toves did gyre and gimble in the wabe [entries|archive|friends|userinfo]
Thomas

[ website | Beware the Jabberwock... ]
[ deviantArt | the-boggyb ]
[ FanFiction | Torkell ]
[ Tumblr | torkellr ]

Links
[Random links| BBC news | Vulture Central | Slashdot | Dangerous Prototypes | LWN | Raspberry Pi]
[Fellow blogs| a Half Empty Glass | the Broken Cube | The Music Jungle | Please remove your feet | A letter from home]
[Other haunts| Un4seen Developments | Jazz 2 Online | EmuTalk.net | Feng's shui]

[Friday 25th March 2011 at 10:30 pm]
Thomas

boggyb
[Tags|]
[Feeling |annoyedannoyed]

A collection of mini-rants today, from a couple of hours spent hacking together a bit of PHP:

  1. Which numpty decided that the default behaviour of a switch statement should be to fall through. It's almost never what you want!
  2. 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.
  3. Why does PHP not have a usable variable type for dates? Even classic VB has one!
Link | Previous Entry | Share | Next Entry[ 4 pennies | Penny for your thoughts? ]

Comments:
[User Picture]From: crschmidt
Saturday 26th March 2011 at 1:07 pm (UTC)
... In what world are the first two different than... well, everything?

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?
(Reply) (Thread)
[User Picture]From: boggyb
Saturday 26th March 2011 at 8:53 pm (UTC)
You're right, they're both carryovers from C, but that doesn't necessarily mean they should behave like that (languages that aren't derivered from C syntax tend to have the non-C behaviour).

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.
(Reply) (Parent) (Thread)
[User Picture]From: crschmidt
Saturday 26th March 2011 at 11:26 pm (UTC)
The last thing, I feel you on, though I've never had any experience with a language that has strong date support built in. Python is closest, but calling datetime objects reasonable would be a stretch, in my opinion. PHP isn't any better or worse than most in that regard: everything pretty much sucks.

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 :)
(Reply) (Parent) (Thread)
[User Picture]From: boggyb
Saturday 26th March 2011 at 11:39 pm (UTC)
I did a bit of programming in BASIC, but the first language I used in anger was Visual Basic 6. It was only later that I started programming in C++ (with MS Visual C++, so that was with the MFC library rather than the classic C one) and I didn't touch Java until starting university.

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).
(Reply) (Parent) (Thread)