From: Robert Dober Date: 2006-10-07T03:09:14+09:00 Subject: Re: nil being empty ------=_Part_132950_30116311.1160158151555 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 10/6/06, dblack@wobblini.net wrote: > > Hi -- > > On Fri, 6 Oct 2006, Robert Dober wrote: > > > On 10/6/06, dblack@wobblini.net wrote: > >> > >> On Fri, 6 Oct 2006, Ohad Lutzky wrote: > >> > >> > Show of hands - who thinks this is bad form? > >> > > >> > class NilClass > >> > def empty?; true; end > >> > end > >> > >> /me raises hand. > > > > > > I feel this being an unnecessary generalization. > > Probably it is very often not the best way to treat the problem, bu= t > > it might as easily be the most elegant. > > Instead of raising your hand David, please speak out ;) > > The idea of measuring whether or not nil is "empty" is like measuring > whether or not 1001 is "blue", or defining a method called > FalseClass#scan(regex). Yes David I agree 100%, but... sometimes nil might be a natural model for something considered empty, anyway I *cannot* come up with a useful example, all examples I have seen seem to indicate that you are right, you, James, Ara, but, but I have a very great dislike for Dogmas. Probably we would all, even me ;) recognize a useful example, I dunno. > Now it would be unfair to ask others for their wisdom without delivering > my > > own (as small as it might be). > > > > If you define your small little NilClass monkeypatch above because you > had > > nils where you expected containers, guess what I think of your code ;) > > If on the other hand the NilClass Emptyness is integral part of your > design, > > document it well and go ahead! > > Ruby is a Tool not a Religion. (well at least I think so ;) > > Since Ruby lets you define or not define nil#empty?, not defining it > is no more "religious", in the sense I think you mean it, than > defining it -- and in general, religious imagery is about as related > to programming as empty? is to nil :-) It's just a discussion about > best practices. > > > David > > -- > David A. Black | dblack@wobblini.net > Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] > DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] > [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com > [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org > > --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_132950_30116311.1160158151555--