Alexey Verkhovsky wrote:
On 5/31/07, Eric Armstrong <[EMAIL PROTECTED]> wrote:
Ruby Code:
- always use && and ||, not 'and' and 'or'

Why is that? For consistency with Java? Or is there
some other benefit?

This is a convention in Rails core. Its origin is that 'and' and 'or'
have priority lower  than && and ||, and lower than assignment. Which
sometimes leads to unexpected behavior.

E.g.
x = y  && z

is not the same as

x = y and z

Good golly. Lower than "="? Horrors. That's the kind of
thing that gives me fits--synonymous terms that have
semantically different behavior. It's just a bad choice.

I'm really glad I asked. It's the kind of thing you could
stare at for an hour, wondering what's wrong.

I would append the statement to read:
  "Always use && and || in conditionals, rather than 'and'
   and 'or'. (Since the latter have lower precedence even
   than assignment, they can lead to unexpected behaviors.)"

Add the exception for control flow, if you must. But I try
not recall such trivialities as precedence. That's important
for a language designer to know, but its something a
language user shouldn't have to understand to use the
language effectively. (So yes, I parenthesize the hell out
of my expressions.)
:_)

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to