Hi --

On Sun, 10 Nov 2002, ahoward wrote:

> On Sun, 10 Nov 2002 dblack / candle.superlink.net wrote:
>
> > Why not:
> >
> >   self.class.new    # type is deprecated, I think, and the 'send'
> >                     # is unnecessary
> [snip]
>
> just trying to make people notice/understand my meaning.  it worked...

Don't worry, most of us know what #new does :-)

> [snip]
> > I don't think it's a style question; it's really a question of what
> > you want your method to do.  I think much/most of the discussion on
> > this has revolved around the question of whether the behavior of the
> > core classes is optimal in this regard.  When it comes to your own
> > code, you can do whatever's best in a given case.
> [snip]
>
> i disagree here.  i love the open source mentality of ruby, the raa seems to
> grow exponentially, and user classes can quickly become 'core' classes.  so
> think it would be good if these 'style' issues could be hashed out.  like it
> or not, the rididity and accepted 'standards' of java coding (like say
> javadoc'ing your code) has definitely help the proliferation of third party
> libraries.  being able to expect things from modules is a good thing IMHO.

But what exactly would that mean in this case?  Does every method of
every class have to return an object of that class?

Given this:

  class Child < Parent
    ...

Child might have methods which return arrays, numbers, strings,
self.class.new's, Parents, etc.  I don't think there's any way to
universalize what should happen, though there may be scenarios I'm not
thinking of.

> > Does that mean you would never override any method?  That seems awfully
> > restrictive as a design principle.
> [snip]
>
> not at all...  but i do prefer
>
>   class Child < Parent
>
>     # original behavior extended
>     def method(*args)
>       super
>       @sub_class_var = 42
>     end
>
>   end
>
> to
>   class Child < Parent
>
>     # original behavior clobbered
>     def method(*args)
>       @sub_class_var = 42
>     end
>
>   end
>
> when at all possible.

This is a question of how much implementation will or should be shared
with an antecedent class or module, and I think it's hard to make a
rule for it.  For example, if the super method consists of 'raise "Not
implemented!"', you probably don't want to call it :-)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav