J
John Carter
A very simple and generic way of improving the reliability of Ruby
programs is to implement the NullObject pattern by allowing nil to
accept all and every method instead of throwing a NoMethodError.
Not only does this simplify ruby programs considerably, it also
changes certain crash bugs silently into correct programs.
If you were to investigate most cases where an if statement checks to
see if a value is non-nil, you will find that the else clause is
empty. ie. Does nothing.
I expect if this is accepted to see a bunch of knock on RCR's, namely
nil+n == n
nil * 7 == 0
-nil == 0
We already have
nil.to_s == ""
nil.to_i == 0
nil.to_f == 0.0
Doing an informal subsampling of the standard libs, I can see no
instances where this change will cause a problem, several cases where
this change could substantially simplify code, and several cases where
this change would result in The Right Thing happening instead of a
crash if the routine was fed a nil.
John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand
Somewhere on the edge of a Galaxy, one of literally billions of such
galaxies, is a sun, one of literally billions of suns in that
galaxy.
Orbiting that sun is a small rock 330000 times smaller than that
sun.
This rock is covered by a very very thin scum of life. (Think 6000km
of rock followed by a meter or so of biomass.)
Amongst the millions of species in that scum are many hundreds of
thousands of types beetle and a mere handful of primates.
Surprisingly enough, this email does not originate from a beetle.
It originates from just one of the 6 billion vastly outnumbered humans.
I trust you will keep this perspective and context in mind when
reacting to this email.
programs is to implement the NullObject pattern by allowing nil to
accept all and every method instead of throwing a NoMethodError.
Not only does this simplify ruby programs considerably, it also
changes certain crash bugs silently into correct programs.
If you were to investigate most cases where an if statement checks to
see if a value is non-nil, you will find that the else clause is
empty. ie. Does nothing.
I expect if this is accepted to see a bunch of knock on RCR's, namely
nil+n == n
nil * 7 == 0
-nil == 0
We already have
nil.to_s == ""
nil.to_i == 0
nil.to_f == 0.0
Doing an informal subsampling of the standard libs, I can see no
instances where this change will cause a problem, several cases where
this change could substantially simplify code, and several cases where
this change would result in The Right Thing happening instead of a
crash if the routine was fed a nil.
John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand
Somewhere on the edge of a Galaxy, one of literally billions of such
galaxies, is a sun, one of literally billions of suns in that
galaxy.
Orbiting that sun is a small rock 330000 times smaller than that
sun.
This rock is covered by a very very thin scum of life. (Think 6000km
of rock followed by a meter or so of biomass.)
Amongst the millions of species in that scum are many hundreds of
thousands of types beetle and a mere handful of primates.
Surprisingly enough, this email does not originate from a beetle.
It originates from just one of the 6 billion vastly outnumbered humans.
I trust you will keep this perspective and context in mind when
reacting to this email.