From: Calvin Bornhofen Date: 2013-01-06T01:00:16+09:00 Subject: Re: Best practice for &&, ||, and, or Hello, I want to use a consistent style so I don't have to think about the precedences that much. This and the fact that I more frequently use && and || brings me to the conclusion that 1. is just more useful, because I have to write less parentheses which in turn make the code easier to read (at least imo). This also makes it easier to learn Ruby/programming for newbies. Compare: foo = hsh[:bar] || hsh[:alternative] || "" # I think lines like these are quite common, because many libraries like to use hashes as parameters and initialization like this is very expressive to foo = ( hsh[:bar] or hsh[:alternative] or "" ) # I think the additional parentheses just distract from what I want to accomplish, which is just an initialization. Parentheses to me always smell like complex computation (which this is not) In my opinion using || in this case is more clear, because you can read the || as "or". And one thing I want to add to your third proposed practice: In the case of "loot = give_money or die" I'd almost certainly think that the or is evaluated before the assignment (just because of the different precedences) at first. Just my two cents. Regards, Calvin On 05.01.2013 13:35, sto.mar@web.de wrote: > a. in the context of your own projects, and > b. with regard to teaching programming newbies > > The GitHub Ruby Styleguide [1] states: "The and and or keywords are > banned. It's just not worth it. Always use && and || instead". > > So what's your practice/recommendation: > > 1. use only &&, || > 2. use only `and', `or' > 3. distinguish between boolean expressions (if this && that) > and control flow (loot = give_money or die) > 4. ???