From: sto.mar@... Date: 2013-01-06T17:33:51+09:00 Subject: Re: Best practice for &&, ||, and, or Am 06.01.2013 05:56, schrieb Jan E.: > Dave Aronson wrote in post #1091178: >> No! No! 1000.times :no! ;-) >> >> Consider the difference between "x = true && false" and "x = true and >> false". Since && has HIGHER precedence than =, "x = true && false" is >> equivalent to "x = (true && false)", just as you might expect. > > Why would I expect that? Why would I even *use* assignments in "if" > statements? I think Dave was not talking about an assignment in an if statement, just a "pure" assignment of a boolean expression to a variable. [...] > Maybe my programming style is totally out of fashion, but my "if" > statements usually look like this: > > if and ( or ) > ... > end [...] > When I want to do "magic" like > > var = val || alt > > then I do use &&/||. But this is a very different context. What I do not like about this approach is that the used operators depend on the context (condition in if statement / condition assigned to a variable), not on the purpose (condition vs. control flow). Every time you want to refactor an if statement by pulling out the condition into a variable you have to change operators: if condition_one and condition_two ... end becomes valid = condition_one && condition_two if valid ... end No "magic" is involved here. Regards, Marcus --