From: Mark Sparshatt Date: 2005-05-07T19:17:38+09:00 Subject: Re: Prove me Wrong! Re: RCR 303: nil should accept missing methods --- Cyent wrote: > On Sat, 07 May 2005 03:06:12 +0900, Patrick Hurley > wrote: > > > On 5/5/05, John Carter > 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.yahoo.com