[Python-Dev] Class Methods

Greg Ewing greg at cosc.canterbury.ac.nz
Mon Apr 23 01:27:14 EDT 2001


Guido:

> The problem is that if you write C.spam, there could be two spams: one
> in C.__dict__, one in M.__dict__.  Which one to use?  How does
> Smalltalk resolve this?

The problem doesn't arise in Smalltalk, because method calls and
instance variable accesses are completely different things and are
handled by quite separate syntaxes and mechanisms.

Python creates problems for itself here by confusing instance
variables of the class with metadata about the instance's methods,
and keeping them both in the same namespace.

Thomas Heller <thomas.heller at ion-tof.com>:

> I'm walking on thin ice here (maybe I should better try it out),
> but IIRC Smalltalk requires to explicit:
> 
>     self class method;
> or
>     self method;

No, to call a class method in Smalltalk, you just send a message 
to the class itself rather than an instance. There's no difference
in the message sending syntax.

> Thin ice again I'm on here (even more), but I have the impression
> that creating a class Point in Smalltalk _automatically_ creates
> two classes: Point and PointClass. The latter is normally hidden
> (but contains the class methods of Point as instance methods).

Yes. You don't normally get a choice about what the metaclass is,
although no doubt you could reach under the covers and manually
construct your own metaclass and instantiate it if you wanted.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Python-list mailing list