From: Robert Klemme Date: 2003-07-17T22:35:58+09:00 Subject: Re: Keyword "with" "Hal E. Fulton" schrieb im Newsbeitrag news:0f0f01c34b9b$1dc0e220$0300a8c0@austin.rr.com... > ----- Original Message ----- > From: "Brian Candler" > To: "ruby-talk ML" > Sent: Wednesday, July 16, 2003 7:03 AM > Subject: Re: Keyword "with" > > > > On Wed, Jul 16, 2003 at 08:27:04PM +0900, Mark J. Reed wrote: > > > On Wed, Jul 16, 2003 at 06:41:11PM +0900, Mauricio Fern�ndez wrote: > > > > > module Kernel > > > > > def with(obj, &blk) > > > > > obj.instance_eval &blk > > > > > end > > > > > end > > > > > > This has apparently been proposed before. The resistance to > > > including it may simply come from the fact that, from a general > > > design perspective, instance_eval is a Bad Thing(TM). It violates > > > encapsulation and removes an object's ability to manage its own data. > > As regards the encapsulation issue -- it depends on > how the real 'with' was implemented. If it were a > real language construct and not just a call of > instance_eval, then stuff inside the block could be > interpreted as calls to accessors and we could disallow > direct access to instance vars. Yes, that's a good point: the instance_eval trick has the drawback that instance variables of the other instance can be referenced. This can lead to confusion and errors that are hard to find. I regard this the major argument against the version of "with" that uses instance_eval. Thank you all for helping in clearing my mind! > Then it just becomes a shorthand -- which is the whole > point after all, I think. Yes, exactly. > I think a big reason 'with' has not been accepted is that > Matz remains unconvinced. It's rather a Pascalism, and I > recall he said he never liked Pascal. Ooops... :-) (Does anybody listen? No? Ok: I admit that I like Pascal as a language for learning. It has some shortcomings especially with regard to IO but it provides a verbose syntax that makes programs easy to read and understand. But don't tell matz...) :-) Cheers robert