Prothon Prototypes vs Python Classes

Joe Mason joe at notcharles.ca
Wed Mar 31 21:56:31 EST 2004


In article <69cbbef2.0403311324.32837704 at posting.google.com>, has wrote:
> Joe Mason <joe at notcharles.ca> wrote in message news:<slrnc6e2sm.fhj.joe at gate.notcharles.ca>...
>> In article <69cbbef2.0403280928.438d194f at posting.google.com>, has wrote:
>> > # Library pseudocode
>> > 
>> > _fooRegistry = []
>> > 
>> > obj _Foo: # prototype object
>> >     # Foo's code goes here
>> > 
>> > def Foo(): # constructor function
>> >     newFoo = _Foo.copy()
>> >     _fooRegistry.append(newFoo)
>> >     return newFoo
>> > 
>> > 
>> > Dirt simple with not an ounce of class metaprogramming in sight.
>> 
>> Is Foo() the standard syntax for making a new _Foo object?  If this is a
>> new wrapper you just created, then it's no different than adding a
>> register() method - the user has to know that something different is
>> being done.
>> 
>> If Foo() is the standard syntax, and you're just overriding the
>> implementation here, does that get inherited?  If so, this missed the
>> condition that only some of the descendants should get added to the
>> registry.  If not - well, inheriting the constructor seems like the more
>> useful behaviour in general, so why not?
> 
> Don't think you've quite got the point of prototype-based OO yet.
> There's no real 'standard syntax' for making objects; nor is there any
> inheritance, classes, metaclasses, or instances. To create a new
> object from scratch, execute the code that defines it. Alternatively,
> duplicate an existing object.

There certainly is a standard syntax for making objects.  I need to know
how to "duplicate an existing object".  Is it "obj.dup()"?
"obj.clone()"?  "duplicate obj"?  Most probably, the language (or
standard library) defines one of these, and I expect most objects to be
duplicated in the same way.

If I want to duplicate an object and add it to a registry, I can
obviously say "obj2 = obj.dup(); registery.append(obj2)".  But if I were
designing a library defining objects of this type which were *always*
intended to be added the registry, it would be preferable for the
standard "obj.dup()" syntax to do this automatically as well, so the
user doesn't need to know about the extra registry step.

Whether it's "the point" of prototype-based OO or not, such hiding of
complexity is a valuable thing for the language to do.  If it turns out
that you just can't do this because it's not part of the philosophy,
then the philosophy is lacking.  (Unless you can give me an equivalent
procedure which is covered by the philosophy, and demonstrate that it's
just as good.)


In the example you gave, the way to make this object was "Foo()".
Because we're talking about several different languages here, which have
syntax which are mild variations on each other, it can be confusing to
tell what exactly a bit of posted code is referring to.  That's why I
asked (rhetorically) if "Foo()" was the standard way to create an
object.  I assume you're talking about Prothon, in which it *is*.  In
that case, my second question stands - how do you inherit the behaviour
of adding to the registry, without rewriting the "_fooRegistry.append()"
line for each cloned object?

Joe



More information about the Python-list mailing list