On 8/10/05, John Carter <john.carter / tait.co.nz> wrote: > On Wed, 10 Aug 2005, Austin Ziegler wrote: >> On 8/10/05, BearItAll <bearitall / rassler.co.uk> wrote: >>> On Wed, 10 Aug 2005 14:44:15 +0900, John Carter wrote: >>>> class NilClass >>>> def empty? >>>> true >>>> end >>>> end >>>> if a.empty? >>> I vote for this one because a good programmer is a lazy sod. >>> Where ever you would end up doing a thing more than once, write >>> it is such a way that you never have to type it again. >> Just, please, don't do it in a library that you unleash on the >> rest of the world. It changes the contract for +nil+, and I >> prefer that it *not* respond to #empty?, because the concept >> isn't *quite* accurate. > I did say long and loud and tediously in the RCR 303 discussion > that we there are several meanings to nil and we need to change > ruby to distinguish between them. I didn't go into detail there, John, but it's worth noting that originally Codd thought that there should be several different NULL values for relational databases. Later in life, he came to believe that NULL values (both the single NULL value in SQL databases and the multiple NULL values in his original relational papers) were bad. > The original poster had a NoThing type of nil. Your fear arises > from the possibility of applying the empty? method to an > Unitialized or NotApplicable type of nil. Your proposal of multiple types of nil makes life harder. Instead of: if foo.nil? # blah end I would have to do: if foo.nothing? or foo.undefined? or foo.not_applicable? # blah end The problem, as others have stated, is that adding #empty? to NilClass implies a containment. I'd have as big a problem if we added #empty? to Fixnum so that 0 returned true and everything else returned false. (Indeed, would that be correct? Would -3.empty? be true or false?) Better to do: if foo.nil? or foo.empty? # blah end The code is explicit and meaningful at that point. Multiple types of NULL/nil values tend to confuse things far more than they help things. -austin -- Austin Ziegler * halostatue / gmail.com * Alternate: austin / halostatue.ca