pet peeves

Pet peeve #1 - the comparison operator

I have a lot of pet peeves when it comes to programming, databases, web content, food, beer, and, well just about everyting. I am thinking of making a series of pet peeves here on this site. Some will seem like plain rants, and others will be more like tips.

When making comparisons, switch the order of the things you compare like this:

if ('book' == $node->type) {
  // Stuff happens
}

You might think why? And that looks weird! Yes, it does look a little weird. But I do this to not accidentially assign the $node->type the value I am comparing it with. It is hell to find an error like this when debugging:
if ($node->type = 'book') {
  // Stuff happens whether you like it or not
}
Read more »

Syndicate content
Theme provided by Danang Probo Sayekti.