- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Why didn't they just use Google's search API?
Admin
Not to mention threadsafe.
Admin
Admin
That's why simplexml and tidy are both available, now isn't it.
Admin
10 Dude what's mine say? 20 Sweet what's mine say? 30 GOTO 10
captcha: nulla
Admin
16K? pfff...high roller, I guess.
Admin
I'm impressed, no obscure TLA's, no misquoted Simpson's episodes, no accusations of incompitence, no grammatical abortions like "looks like it doesn't know there ass from a whole in teh ground". Instead, just good solid advice on how to code well.
I for one, read this site to learn what not to do. I've been doing this stuff for a long time and I still occassionally find examples of things I have done before.
It amazes me that those who instantly resort to nastiness can't see just how foolish and insecure they look. They'll be the first ones to blame a PM or business owner for bad direction when they're caught doing something stupid. And every one of us, without exception, will at some point be caught doing something stupid.
Thanks for the good post.
Admin
Case in point: not using the Quote feature.
Admin
Yeah. Thought I was l33t for about 6 days. Then it was "WTF? You can program colors?!".
Admin
I was thinking, "Heh, this looks like all the PHP code I've ever seen. What's the big deal? At least it isn't full of HTML."
Admin
Admin
For me, the gem has to be this line:
if (substr($u,0,4)==='/url') ...
I don't know under what undocumented circumstances substr() would return a type other than string, and even then, how whatever it returned instead could still == '/url'.
As much as I like PHP, part of me screams that "===" is TRWTF anyway -- functions that can return 0 or false, and you need a dedicated operator to figure out what you got.
As much as some people here loathe Perl, I'm finding far fewer genuinely stupid ideas like that in Perl. One strange gotcha is this:
someFunc($a, $q->param('does not exist'), $c);
You'd expect this to evaluate to the following:
someFunc($a, undef, $c);
but since actual parameters to a function are nothing more than a list, CGI::param detects list context and returns an empty array, so you get:
someFunc($a, (), $c);
which is the same as:
someFunc($a, $c);
Suddenly, your function has argument 3 where 2 should be, and argument 3 is missing.
Admin
It's a multiple cock-up, really. Whereas the parameters to a function are (obviously) presented as a list, this surely does not mean that they should be individually evaluated in a list context. Thus, it really should be undef and not "an empty list."
Next up, we have Perl's notorious list-flattening mechanism. Any other language would treat the (erroneous) empty list as a reference to an empty list in this context ... which, happily, would have the same result as the intuitive behaviour, in all but corner cases.
This stuff happens all too frequently, largely because of Perl's supposed willingness to "do what you wanted to do" without complaining. Good concept, but slightly flawed when it actually does something radically different from what you wanted to do.
I've lost count of the number of times I get caught out when interpolating some trivial Perl expression like $q->param('Urban Spaceman'), only to see gibberish like HASH(0xC34A701) appear in the output. These days, I just hoist anything and everything into a local variable ... not significantly slower, much clearer, and makes debugging with something like Komodo a hell of a lot easier.
Admin
Something I nearly wrote but didn't -- as I felt I'd only get flamed again -- was that in BBC BASIC, functions had no defined return type. Instead of DEF FNfoo$ or DEF FNbar%, functions could return whatever they felt like. I thought that this silliness was just a limitation of the 16 k paged slot for BASIC, but apparently Perl's CGI took this idea to heart. A function that can return either a list or a scalar to me is simply broken.
You do have to be extremely careful with references. A reference to an empty list equates to true in boolean context and passes defined(), but contains nonsensical data if you were looking for a scalar. This is where your nice undef (e.g. disabled or not-completed HTML field) would end up "HASH(0xC34A701)".
Overall, though, I am really enjoying Perl. I should have learnt Perl a long time ago!