From: Nicholas Van Weerdenburg Date: 2004-05-20T09:40:40+09:00 Subject: Re: 0 is a Number, too! Not to beat a dead horse, but semantically Ruby's mechanism makes sense to me from a coding perspective. Once nil exists and is well used by existing libraries, what cases exist for if(0) or if (1) (after the expression evaluates)? Those cases in other languages are usually for existence or non-existence or a comparison that doesn't have anything to do with existence or non-existence (e.g. > 100). Since we often test for non-existence or existence, it is worth looking at letting existing objects automatically say "true" meaning "I exist" and nil objects say "false", meaning I don't exist. We gain a nice syntactic shortcut, but does it cost us clarity or meaning for other syntactical use cases? I don't think so- or at least I haven't noticed it. I guess if( 0 ) evaluating to true is a bit confusing due to C conventions, but that is quickly overcome and the elegance gained is nice. 3 things evaluate to a boolean- an objects existence, it's non-existence, or a boolean. The first two being nice shortcuts. Logically, it makes sense to me. Can anyone think of ugly syntacical repercussions from this point of view? Dave Burt wrote: >This "geeky kind of logic" is a legacy that disrespects 0: > > >David Naseby wrote: > > >>I'd contend there's more of a "geeky >>kind of logic" in 0 meaning false. >> >> > > >Tim Bates wrote: > > >>This "geeky kind of logic" comes from back in the bad old days when >>everyone wrote in assembly language (or C, which has all the power and >>flexibility of assembly language with all the portability of assembly >>language...). In those days, you didn't have bools, or floats, or >>strings - all you had were ints and arrays of ints. So one represented a >>false value as 0 and a true value as 1 (or nonzero). >> >> > > >Equal rights for Numbers: 0 is a Number, too! > >Sure, Numbers are Comparable. Sure, 0 might be less than some other Numbers, >but it's greater than some Numbers, too. > >No Number should be considered false. No Number deserves to be considered >false. > >No Number has the negativity and emptiness that nil and false exude. All >Numbers are on if's guest list[1]. > >Granted, in the past it's true that 0 had no bits set. It took on the roles >of false and even nil even when the need was there. > >Give it credit for that! Respect, too, that all Numbers, yes, even 0, have >an id now. > >I dream of the day programmers esteem 0 as highly as mathematicians. > >Respect all Numbers equally. Join the fight for equal rights for 0. > >honk if 0 > > > >(Besides, it's just a simpler rule -- only false and nil are false) > >[1] http://www.poignantguide.net/ruby/chapter-4.html#section2 > > > > >