On Sun, 25 Feb 2001, David Alan Black wrote:
> I'm probably just being inattentive, but until very recently I don't
> remember ever seeing terms in comparisons put in a constant-first
> order.
> 
> By which (in case my terminology is inexact) I mean things like:
> 
>    if [] == ary
>    if "" == str
> 
> rather than
> 
>    if ary == []
>    if str == ""
> 
I first saw this in the book, "Writing Solid Code" by Steve Maguire 
(1993). The idea is to prevent hard to find bugs (in C or C++) such as:

if (x = 5)
{
  // do something
}

Lint would pick up the assignment within the if, but most compilers won't
generate a warning. If you get in the habbit of writing

if (5 = x)
{
  // do something
}

then your compiler will flag this as an error.
gcc returns: invalid lvalue in assignment

but says nothing with 'if (x=5)'.

It's not a perfect solution, but it has saved me a couple of times from
minutes to hours of searching. I found it especially useful in untyped
languages such as PHP and Perl.

=========================================================
Jim Freeze
jim / freeze.org
---------------------------------------------------------
"So, it should be relatively easy ... this is the phrase
I use when someone else is the most obvious person to do
something."
      Harry Ohlsen
=========================================================