Subscribe to RSS Feed

Categories

Archives

NDD: Niggly Detail Of The Day

↓ skip to article

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->searchhelp(1);
} else {
      $self->searchhelp;
}
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 searchhelp, 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->searchhelp;
}
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.

Comments (No comments)

There are no comments for this post so far.

Post a comment