News for hackers. Stuff that matters.
Re:Ruby Tips Part 1 by Xylakant on Monday September 02, 2013 @12:46PM (#6315914)
yes. The first one does what it's intended to, the second plain fails :)

    Voice-of-Evening:~ $ irb
    irb(main):001:0> max=Float::INFINITY
    => Infinity
    irb(main):002:0> i = 0
    => 0
    irb(main):003:0> i < max
    => true
    irb(main):004:0> max = nil
    => nil
    irb(main):005:0> max && i < max
    => nil
The second version will only provide any result when a specific max value was given, while the first one will loop into infinity.
Re:Ruby Tips Part 1 by hk__2 on Monday September 02, 2013 @05:11PM (#6317211)
Yes, I messed up. I meant `!max && i < max`.
Re:Ruby Tips Part 1 by Xylakant on Tuesday September 03, 2013 @02:38AM (#6319378)
Then the code is functionally equivalent, but the first version is much more readable. As pointed out on the parent comment, the first version does one test less, a minor performance benefit.