On Thursday, December 12, 2002, at 10:39 AM, Chris Pine wrote:

> [snip]

> 1.  we could get rid of singleton classes altogether, in favor of 
> simply
> inserting real classes into the hierarchy.

> [snip]
2.  This just tells me that Class.new is broken.
> [snip]
3.  This would also encourage people
to use #kind_of? instead of #class, which is a Good Thing.
> [snip]
4.  if there are other problems with
subclassing Class (in principle, not in the current implementation), 
please
tell me what they are.
> [snip]


1.  I don't see the practical problem with having singleton classes and 
I do see benefits to having a direct implementation of a useful design 
pattern.

 From http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/patterns/

"The singleton pattern applies to the many situations in which there 
needs to be a single instance of a class, a single object. . . .  An 
important consideration in implementing this pattern is how to make 
this single instance easily accessible by many other objects.

. . .

What are the advantages to using this pattern?

Single instance is controlled absolutely. When implemented as the 
pattern recommends, the class will have direct control over how many 
instances can be created. This is in contrast to making the programmer 
responsible for insuring that there is only one instance.

This pattern is easily extensible to allow a controlled number of 
"singleton" objects to be created. The most important modification 
needed to accomplish this change is in the operator that has control 
over access to the instances. In this case, the Instance() function 
would need to be changed."

2.  I don't see a sound basis for saying that Class.new is broken.

3.  I don't see why the kind_of? method is any more preferable to the 
class method.

4.  Can't one come to understand language design principles by 
increasing one's understanding of an implementation like Ruby?

Thank you for a thought-provoking discussion.