On May 12, 9:27 am, Brian Candler <B.Cand... / pobox.com> wrote:
> 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.

There are a number of advantages to sub-classing that I can think of:

  1)  No need to do x.to_s.some_string_method.to_sym

  2)  Hash keys could efficiently equate symbol and string keys (it's
the distinction that should be optional)

  3)  It's conceptually simpler: a Symbol is an immutable String.

I'm sure there are a few more. On the downside, Symbols might not be
as efficient in general, and there could be some back-compatibility
issues.

Would be interesting to know what effectively killed the official
attempt at this.

T.