Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: Prove me Wrong! Re: RCR 303: nil should accept missing methods
mark sparshatt
5/7/2005 10:18:00 AM
--- Cyent <cyent@xtra.co.nz> wrote:
> On Sat, 07 May 2005 03:06:12 +0900, Patrick Hurley
> wrote:
>
> > On 5/5/05, John Carter <john.carter@tait.co.nz>
> wrote:
> >> I would suggest next 5 times you have a nil class
> throws
> >> NoMethodError crash, just add this at the head of
> your program...
> >>
> >> class NilClass
> >> def method_missing( sym, *args)
> >> nil
> >> end
> >> end
> >>
> >> And see what happens.
> >>
> >> If, your program then works correctly, then I am
> right.
> >>
> >> If, your still program thows an exception or
> reports an error, but perhaps
> >> a slightly different point, then I am still
> right, namely this change
> >> doesn't hide bugs.
> >>
> >> If the program silent proceeds to do the wrong
> thing, then I am wrong.
> >
> >
> > A simple example of "wrong" behavior (using the
> nil returns of !
> > methods which is another can of worms :-)
> >
> > class NilClass
> > def method_missing(sym, *args)
> > nil
> > end
> > end
> >
> > x = "Pat"
> > x.strip!.upcase!
> >
> > #use x in some important way....
> > # this now fails silently, the expectation
> > # was for an upcased string with no "extra" white
> space....
> > puts x
>
> That's not a failure, thats a confirmation.
>
> You asked for an upcase string with no whitespace.
> You have got one.
>
> Wheres the problem?
>
> You didn't ask for a non-empty string...
>
I'd guess the problem is that x is now supposed to be
an upper case string, it isn't it's still set to "Pat"
If at some point there is some code that depends on x
being uppercase then the program will fail in the
wrong place, making debugging harder.
Even worse if x is used to generate some content, and
the format for that content mandates that it should be
all uppercase then you'll just get bad data with very
little indication of where the problem is.
--
Mark Sparshatt
___________________________________________________________
How much free photo storage do you get? Store your holiday
snaps for FREE with Yahoo! Photos
http://uk.photos...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Prove me Wrong! Re: RCR 303: nil should accept missing methods
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password