On Jun 14, 2007, at 3:38 PM, Eric Armstrong wrote:
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.
That's just it--they're not synonymous. && has a higher precedence
than ||.
"and" has the same precedence as "or."
Compare these two:
puts "I print " if true || true && false
puts "But I do not" if true or true and false
Use "and" and "or" if you know what they do.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email