From: Michal Suchanek Date: 2007-06-25T19:06:46+09:00 Subject: Re: avoiding nil.methodcalls short and cheap On 22/06/07, Eivind Eklund wrote: > On 6/22/07, Michal Suchanek wrote: > > I would avoid code that relies on logical operators to preserve values. > > That is any code that uses logical operators and would break if you > > put !!() around the expression is quite dodgy in my book. > > And I would strongly disagree with this. > > Returning the value of the true expression is defined behavior, and it > allows for considerable simplification of code. Having simpler code > means that you have less chance of errors and spend less time when > reading the code. > Not always. It is defined behavior but unless you work exclusively in Ruby you will have to deal with cases when true values are not preserved. This makes the code more obscure, harder to read, and more error prone. The concept of logical operations is to preserve the logical value, and you have to think twice about other properties they might or might not have. Thanks Michal