From: Robert Klemme Date: 2005-05-07T16:44:28+09:00 Subject: Re: RCR 303: nil should accept missing methods and return nil "Cyent" schrieb im Newsbeitrag news:pan.2005.05.07.00.06.00.185009@xtra.co.nz... > On Fri, 06 May 2005 12:12:35 +0200, Robert Klemme wrote: > >> >> I'm sorry, is this some kind of hoax? A program will not magically be >> correct simply because an error is hidden. Think of all the subtle bugs >> this would introduce, for example: you create an array with a fixed >> number >> of elements and forget to give the default value 55. Now math would >> work, >> but the results would be wrong - and you might not even catch this. > > Think of an array with 42 elements. Access element 55. It returns nil. How > is this different? It's not different. But it's not an argument in favor of your suggestion either. > If you think through the default values for arithmetic operations on nil > properly. My guess is the results in most case will be right.(How often do > you initialize an array to 55? 99.9% of the time you expect it to be full > of 0 or maybe 1. > > How about nil autoconverts to the identity element for all operations. ie. > 0 for +, 1 for *, "" for string concat. Not feasible since you would need a custom version of #coerce also and in that method you don't know the operator (+ or * for example) - at least not with standard means. And I would not like to see these perlish dirty tricks in ruby. > In which case more code simplification, more code that just works. If you would drop this "code that just works" maybe I could find something useful in your suggestion. I'm sorry, but I get the impression that you don't really seem to overlook the effects of your suggestion. >> The article at >> http://www.smalltalkchronicles.net/edition2-1/null_object_pattern.htm >> that >> you refer to in the RCR states, that it's a bad idea to introduce this >> change in Smalltalk because it would break too much code. The situation >> in >> Ruby is similar. > > Is it? > > I wwnt grepping through ruby 1.9 CVS (ok its a month or two old version) > looking for some code that will break. > > I don't believe _anything_ will (currently) break. But you should accept that others believe different. robert