From: sto.mar@... Date: 2013-01-12T01:34:18+09:00 Subject: Re: Best practice for &&, ||, and, or Am 05.01.2013 13:35, schrieb sto.mar@web.de: > Hi group, > > I really would be interested in your thoughts about this > > 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". Thanks to all for your interesting input. To sum up: I have come to the conclusion to ban 'and'/'or' completely from my teaching (except for mentioning their existence). In the limited time I have I can only discuss a small subset of the Ruby language anyway, and flow control with 'and'/'or' rather falls in the category of syntactic sugar, especially for a beginner. I have been confirmed in the believe that 'and'/'or' for logical expressions -- though very readable -- is just BAD and dangerous, because the behavior is too surprising. A student (and maybe not only a student) might happily refactor if cond1 and cond2 ... end to condition = cond1 and cond2 if condition ... end without ever noticing that this would break the logic of the code. I still might use 'and'/'or' for flow control in my personal projects, but I use this idiom very seldom anyway and rather prefer if/unless. Regards, Marcus > 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. ??? > > 1. and 2. might require extra parentheses that often could be > avoided with 3., but using parentheses might be clearer anyway. > Especially for students who might have a hard time coping with > the different precedences. > > I tend to 1., and for own projects maybe to 3. > > Regards, > Marcus > > > [1] https://github.com/styleguide/ruby/ --