I was looking through some code today and came across something like this.

if (checkSomeValueInTheDatabase() && someValue == someOtherValue) // Do something...

Now this is a completely legitimate conditional statement. But it's not very performant. You should always use boolean short circuits to your advantage when writing conditional statements. Start with the conditions that are the easiest to evaluate then work your way down to the ones that use a lot of resources, like hitting the database.

The example above I would change around like this.

if (someValue == someOtherValue && checkSomeValueInTheDatabase()) // Do something...

It gives you the exact same result as the first one but it doesn't go out to the database unless the first condition that checks if 2 variables have the same value is true.

I see this a lot when looking through code. So it seems to be a pretty usual problem. That's why I'm writing about it. So the next time you write a conditional statement with many parts to it take a moment to make sure it is optimized to save resources and run faster.