[Python-Dev] Type/class

Steven D. Majewski sdm7g@Virginia.EDU
Fri, 11 May 2001 22:43:31 -0400 (EDT)


On Fri, 11 May 2001, Thomas Heller wrote:

> I never looked at Self or other prototype based systems.
> Is it really true that prototypes are a lot simpler than
> metaclasses, but on the other hand more powerful?

Definitely simpler: No classes, No metaclasses, only objects.

Ignore for now the fact that a limited set of classes are 
handier for a statically type checked language and just 
consider dynamic languages, which is their proper domain.      

Prototype semantics  basicalaly subsume class semantics. 
Any object can be an exemplar and fill the role of a class,
and it can be used ONLY as a template and holder of shared
behaviour, so it can be used like a class. 

[One of the self papers -- one which I haven't read -- is
entitled "Self includes Smalltalk"  -- and is, I believe,
a demonstration that SmallTalk is sort of a subset of Self.]


But you can also have finer grain classification and you 
can have object inheritance. ( This is handly in XlispStat,
which is oriented towards statistics and analysis: you can
have derived objects, for example different subsamples of
the same population, or in my app, different energy spectra,
along with derived and processed spectra with special rules
for treatment: e.g. linear filtered spectra have a filter
function or kernel, and if they are fit against reference
spectra, they need to be fit against references that have 
had the same filter applied to them -- if none available
create one from unfiltered samples -- and maybe a whole
chain of derived data. In a class based system, you would
have to manually maintain a separate linked list of objects,
but in a prototype system they can all be cloned from their
parent objects. )   

The other plus for things like exploratory statistics is that
you don't have to design a class hierarchy ahead of time -- 
it more concrete and less abstract than a class based system.

Prototypes can also solve some of the sort of problems that
Jim Fultons acquisition framework in Zope is designed to 
handle. (But it's been a while since I read that paper and
I haven't used it, so I'm relying on my memory of thinking
"Yeah -- that would be simpler with prototypes" ) 

You definitely don't have to worry about simulating the 
Prototype Pattern. (I've seen GUI systems in C++ that go
thru a lot of code to add prototype-like behavior to C++ classes.) 




But -- unless I can figure a useful way to use it under the
covers, it's not really a topic for python-dev.  



> The 'brain exploding properties' of metaclasses are IMO
> only there because my brain cannot think easily in too
> many recursion steps...

It's just like spelling bananana -- the problem is to know
when to stop! ;-)


-- Steve Majewski