From: Jamis Buck Date: 2004-05-20T02:00:12+09:00 Subject: Re: Zero is true ... whoda thunk? Ben Giddings wrote: > Converting numbers to boolean values is a problem-specific issue, and > shouldn't have a general case. What's so difficult about using tests > like (foo == 0) and (foo > 0) anyhow? Beautiful and well-thought-out explanation. Thanks! I've had to fight uphill against people that want 0 to mean false for a long time. The absolute WORST abuse of 0==false is with strcmp in C (which we use extensively at work): if( !strcmp( string1, string2 ) ) { ... } I'm SO glad that Ruby forces you to compare numbers explicitly, instead of implicitly converting to bool. It makes code that much more readable. -- Jamis Buck jgb3@email.byu.edu http://www.jamisbuck.org/jamis ruby -h | ruby -e 'a=[];readlines.join.scan(/-(.)\[e|Kk(\S*)|le.l(..)e|#!(\S*)/) {|r| a << r.compact.first };puts "\n>#{a.join(%q/ /)}<\n\n"'