From: Albert Wagner Date: 2002-09-06T12:52:28+09:00 Subject: Re: Ruby aesthetics On Thursday 05 September 2002 09:45 pm, dblack@candle.superlink.net wrote: > Hi -- > > On Fri, 6 Sep 2002, Albert Wagner wrote: > > On Thursday 05 September 2002 12:08 pm, Christian Szegedy wrote: > > > > > > > What I really dislike in Ruby, that the data members are seen > > > by the child classes. This is a very serious issue, and a claer > > > violation of object-orientation. > > > > > > I think Ruby would be a much better language if the instance > > > variables would only live per class and not per hierarchy... > > > > I don't understand what is bad about this. I typically depend on > > instance variables in the parent(s) being directly accesssible. > > I think I understand the objection (thanks in large part to Holden's > explaining it to me on irc). As I understand it, the problem is that > if you do this: > > class A > def initialize(x) > @thing = x > end > > def talk > puts "My thing is #{@thing}." > end > end > > class B < A > def talk > puts "I have a thing which is #{@thing}." > end > end > > and then class A is rewritten so that @thing is renamed to @item, B > will break. > > I've tended to see instance variables as part of the... well, I was > going to say the interface, but that's wrong... part of the stuff > you're allowed to know about. But I'm seeing that that's pretty > non-robust. I suppose what is needed is a good refactoring browser for Ruby. Then, in the example above, all references to @thing would be automaticallly renamed in progeny. However, speaking for myself, I don't trust the parent's accessors to not cause side effects. I view instance variables, like methods, as what a subclass inherits. I design and maintain with this is mind. When I change the name of a superclass instance variable, I know to change it in it's subclasses also. Standard operating procedure. > > > David