Put the fastest method
first because if it returns a false you are done.
if ( methodThatWorksInstantly() && methodThatTakesHoursToRun() ) ....
Now, if the first method returns false, the
second method will not be evaluated at all,
saving time.
The result of evaluating the boolean expression will
be false whenever methodThatWorksInstantly() is
false, but with this arrangement sometimes
an expensive method call is skipped.
However this works correctly only if the skipped method
does nothing permanent.
In other words, short-circuit evaluation is safe when
the skipped method does nothing but
compute true or false.
Short-circuit evaluation is not safe when the
skipped does more than that.
For example:
boolean methodThatTakesHoursToRun()
{
// make a permanent change to the state of
// an object that the rest of the program uses.
// now return a true or false
}
When a method makes
permanent changes to data,
it must be called regardless of
the true/false value of some other method.
When a method makes a permanent change to data
the method is said to have a side effect.
When methods have side effects,
you must be careful when using a short-circuit
operator.