Search
Tweets
Recent Changes
« PSA | Main | From Fedora With Love »
Monday
Jul182005

NDD: Niggly Detail Of The Day

The code I've come to own is literally covered in crap like this. This one drove me crazy...

if ( $s->count() == 0 and $s->type() =~ /title/i) {
$self->search_help(1);
} else {
$self->search_help;
}

That snippet was converted to user my new search code last week, and today I was having some odd display errors with my search results. The results were fine, but the 'help' text was showing up.

Turns out, that in the above statement, the '1' argument to search_help, if present, causes it to immediately return. Effectively making it a null op with the overhead of a function call. This was reduced to:

if ( $s->count() == 0 and $s->type() !~ /title/i) {
$self->search_help;
}

UPDATE: Kevin pointed out that the original logic is broken, because if there WERE results, it would break the AND, resulting in a call to search_help(). This was the bug that got me here in the first place, and I fixed it by making the described changes. That is all.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>