On Sat, May 12, 2007 at 04:20:10PM +0900, enduro wrote:
> I was exited when I heard that
> Symbol was made a subclass of String
> in Ruby 1.9, September last year.
> 
> But then I heard that the experiment
> was stopped after only two months.
> 
> And recently I have started to think about this
> topic again and I've tried to collect the reasons
> why the idea was not pursued any longer.
> 
> I have not been very lucky searching the net
> for that, that's why I am asking you:
> 
> Could someone give me a summary of the reasons
> why the approach to make Symbol a subclass of String
> is not considered for future Ruby versions anymore?
> Or point me towards some information explaining that?

The two objects have very different behaviours, so why should one be a
subclass of the other?

* Symbols are immutable, Strings are mutable
* Symbols are singletons, Strings are not

I think this is an example of the traditional OO dilemma: "is Circle a
subclass of Oval, or is Oval a subclass of Circle?" One argument says: a
Circle is a subclass of Oval because you can use an Oval to draw a Circle -
you just need to constrain its parameters. Another argument says: an Oval is
a subclass of Circle because it extends the behaviour of Circle.

Ruby says: we don't care. Make a Circle class, and make an Oval class. Make
them both respond to whatever methods make sense (e.g. all shapes may be
expected to have a 'draw' method). If you want to share implementation code
between them, then use a mixin.

Regards,

Brian.