Simple prototyping in Python

has has.temp2 at virgin.net
Fri Apr 30 12:55:40 EDT 2004


Dave Benjamin <ramen at lackingtalent.com> wrote in message news:<slrnc938vm.1v0.ramen at lackingtalent.com>...
> The recent conversation on prototype-based OOP and the Prothon project has
> been interesting. I've been playing around with the idea for awhile now,
> actually, since I do a lot of programming in JavaScript/ActionScript. I feel
> like people are focusing too much on the "prototype chain", which to me is
> mainly an attempt at reintroducing inheritance. 

It doesn't even do that; at least not in the sense that class-based OO
defines it, where inheritance merely describes the initial state for
every object created from a class.

To me, the way Prothon and Io do "prototypes" feels more like a leaky
abstraction, where a common internal optimisation for proto-OO systems
has somehow leaked out into user-space. See if I ever find that
Lieberman fellow, think I'll be having a word or two with 'im. ;)


> I almost never use
> inheritance anymore, preferring delegation instead in most cases. What I
> think is much more interesting about the prototype-based style is the
> ability to create and pass around anonymous objects. 

In a proto-OO system all objects are _completely_ anonymous*, having
no 'class' and all being of the same type, 'object'. In this respect,
they're just like strings, lists, dicts, or any other 'anonymous'
type; a list is a list is a list, for example, regardless of how it is
used.


(* To the user, anyway. Of course, they still have internal ids so the
runtime can track 'em, but that's not something the user ever needs to
know about.)

> JavaScript has a syntax
> for this:
> 
> var o = {a: 5, b: 6}

Looks on the surface like AppleScript's record type, which is roughly
analogous to C structs... and useless for anything more than
struct-style usage. While I did read about JS programming in the
dim-n-distant past - it was one of a number of languages I looked at
when learning proto-OO on AS, which lacked any decent learning
material on the topic - I've pretty much forgotten everything since.
So can I ask: is the JS structure more flexible; e.g. can one add
functions to it to operate like methods on the other data in the
structure? Or does it have to provide a second structure for proto-OO
use, as AS does?



More information about the Python-list mailing list