On 7/18/07, dblack / wobblini.net <dblack / wobblini.net> wrote:
> Hi --
>
> On Wed, 18 Jul 2007, Robert Dober wrote:
>
> > On 7/18/07, Robert Klemme <shortcutter / googlemail.com> wrote:
> >> 2007/7/18, Jeff Pritchard <jp / jeffpritchard.com>:
> >> > Daniel Lucraft wrote:
> >> > >> On Jul 17, 6:52 pm, Jeff Pritchard <j... / jeffpritchard.com> wrote:
> >> > >>> This could be written:
> >> > >>> blah = (foo.bar||"").split
> >> > >
> >> > > Sometimes I think the brackets spoil how the expression reads. You
> >> could
> >> > > define a method that looks like this:
> >> > >
> >> > > blah = foo.bar.or("").split
> >> > >
> >> > > Trainwreck though...
> >> > >
> >> > > Dan
> >> >
> >> > Thanks everyone.  This has at least convinced me that I wasn't missing
> >> > some well known way to do this.
> >>
> >> I believe another (obvious?) solution has not been mentioned so far:
> > I believe Aur has ...
> >>
> >> # note, I used the empty array as replacement
> >> # because split would return an array
> >> blah = foo.bar.split rescue []
> > ... and I think it is nice.
> >
> > I lost the fight with myself to propose this :)
> >
> > class Nil
> > def split; [] end
> > def join(x); "" end
> > def each &blk; end
> > etc.etc
> > end
> >
> > now there might be many reasons against this, and I believe that they
> > outweight the benefits, but look at this
> >
> > irb(main):005:0> nil.to_i
> > => 0
> > irb(main):006:0> ## and worse
> > irb(main):007:0* Integer(nil)
> > => 0
> >
> > so I am still suffering from Ruby's inconsistency (do not laugh Lionel).
>
> My favorite slogan for Ruby is:
>
>    The triumph of balance over symmetry.
>
> It means, for example, that it might make sense for nil to have #to_s
> -- and that it still might *not* make sense for nil to have #split.
> One does not imply the other.  Every decision is made carefully, one
> at a time, in the interest of the usefulness of the system overall.
I do have problems with such err strict statements, and I have never
seen such from you before. I am however challenging the usefulness of
Integer(nil) =>0  and doubting the usefulness of nil.to_s => 0.
>
> That's why I don't care about symmetry or consistency (which I think
> in this case mean much the same thing).  We're lucky enough to have
> Matz hand-crafting the language with the greatest care; I think that's
> a higher-percentage prospect than a principle of uniformity :-)
No sorry I can only disagree.
Matz has tons of my respect but should that be any reason not to be
consistent or symmetric.

Asymmetrical behavior is not very POLS and once a user has learned
that Integer("david") will throw an exception she will expect the same
for Integer(nil).

nil.to_i => 0 is exactly the same as nil.split => []
expressing equivalancy of different forms of void.
I do not agree with this equivalency but I believe it should be
expressed consistently.

Hmm I feel it is too easy to say look "Ruby is just perfect thus you
shalt not criticize", well that's how I interpreted your reply.

>
>
> David
>
> --
> * Books:
>    RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
>    RUBY FOR RAILS (http://www.manning.com/black)
> * Ruby/Rails training
>      & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)
>
>
Cheers
Robert

-- 
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck