David Alan Black <dblack / candle.superlink.net> wrote:
>
>Hello --
>
>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 don't actually remember *ever* seeing this until perhaps a
>few months ago.  And mainly in Ruby.  (Then again, I've been
>scrutinizing mainly Ruby code for the last few months :-)
>
>Can anyone give me a little history and/or theory on why this
>style is in use?  Or is there a semantic implication I'm not
>seeing?

I don't know about other people, but it is a habit
that I picked up in Perl, to which it comes from
careful C coders.

The problem is that if you have a typo it is very
easy to write:

  if a = []

when you meant to write

  if a == []

and then spend a while tracking down the bug.  OTOH
if you write that (as I do) the other way around
you will get:

  if [] = a

which gives you an error that is easier to track
down.

Cheers,
Ben
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com