What to write about today? I don't have much time for iron man, so I decided to share two recent bummers or quite.
Yesterday I got hit by the following code written by someone else:
if (! $blog->can('allow_html_comment') or ! $blog->allow_html_comment) {
remove_html();
}
First, it's probably better to cleanly define the class/role hierarchy to avoid can() altogether, but sometimes, using can() is just the cheap hack that make it Just Work, so let's let it go.
What I was bitten by is actually in the underlaying allow_html_comment() implementation which I co-wrote. &allow_html_comment is actually installed using AUTOLOAD(), so can() always return false until the first call inside the process, making this conditional evaluation inconsistent depending on the execution order. Aweful.
I guess can() is a semi-bad idea, AUTOLOAD used this way is another semi-bad idea, but both combined make it a really-bad idea.
The second bummer is in this gist: http://gist.github.com/107815
It never occurred to me to use scalar() the way it is used in 'baz', but it occurred to a colleague, do you know what it does and why?