Damian,

On Oct 11, 2005, at 6:53 PM, Damian Conway wrote:
Anyway, I have said my peace, what do you all think?


I think there are serious problems with this proposal. For a start, it would be very difficult to create *any* objects at all if the C<new()> class method wasn't inheritable.

Actually &new should be an instance method of Class, not a class method of Object. Since all classes are instances of Class, then calling Foo.new is just calling an instance method on the instance of Class whose name is Foo.

As for overriding a class specific &new, this is accomplished using singleton-methods on the instance of Class. That &new is then not inherited. I think that this is probably sane, and the BUILD submethod is a far better place to put class specific initialization since your are guaranteed to have all BUILD methods run correct and in-order.

This follows how most other reflective object models work.

In Smalltalk-80 every class has a metaclass, the class itself stores all instance methods for the instance, while the metaclass stores all "class methods" (which are basically instance methods on the metaclass instance). This allows the smalltalk method dispatcher to work exactly the same for both class methods and instance methods. Smalltalk does allow you to define the "new" message for a particular class, but it becomes an instance method of the metaclass.

In CLOS, the generic method 'make-instance' is specialized to 'standard-class', it runs the initializer of each superclass in the class precedence list, but those are instance specific methods.

Ruby uses singleton-methods on the Class instance to create "class methods", which is where the whole eigenclass thing comes from. The result is that class methods are themselves instance methods on the eigenclass (which is very similar to how Smalltalk's metaclass system works).

Also in most of the other literature I have read, the responsibility of creating an instance is relegated to Class, and not to Object (or some other element of the system).

Stevan

Reply via email to