Is classless worth consideration

David MacQuigg dmq at gain.com
Thu Apr 29 15:31:00 EDT 2004


On Wed, 28 Apr 2004 22:48:12 -0400, "John Roth"
<newsgroups at jhrothjr.com> wrote:
>"David MacQuigg" <dmq at gain.com> wrote in message
>news:g9k090lhocd1nbd7g230br6ooub113hjt6 at 4ax.com...
>> The problem we Python programmers are having is understanding the
>> fundamental advantage of eliminating classes and working only with
>> instances.  The theoretical discussions put me to sleep.  I can't see
>> the point of the examples above.  What we need is a simple use case.
>>
>> I've included the ability to clone one instance from another in my
>> "Python 3" proposal
>> http://ece.arizona.edu/~edatools/Python/PrototypeSyntax.htm
>> This will allow the user to completely ignore classes, and just make
>> one instance from another, then another, and so on, modifying each
>> instance along the way, whenever the urge is felt.
>>
>> Here is what I have so far in the Pros and Cons on this feature:
>>
>> Pro:  Allows "on-the-fly" programming style with no classes.
>> Con:  Can lead to more undisciplined programming.
>>
>> Perhaps you can help us here.
>
>So far, I have one use case: text adventure game programming.
>Most of the objects in such games are one-off, and having to
>create a class and an instance for each piece of scenery is more
>than a bit much. This is one of the reasons that standard programming
>languages have never gotten much traction in that domain.
>
>It's just occured to me that backing into that particular
>issue might work: use class methods and never bother
>with instantiating the classes at all. I'm not sure what
>we'd lose. (possibly descriptors?)

So let's see if I can state the problem clearly:  We want to be able
to create many "one-of-a-kind" instances, and the current syntax
requires an extra statement to instantiate each object from a class.
We would like to simply clone an existing instance when we need a new
one, adding whatever changes are needed "on-the-fly".

I've proposed a syntax to do this, and we are now considering the pros
and cons of implementing such a syntax.  Here is an example of using
the syntax:

>>> class S(object):  #  We need one class to get started.
        ... add all common attributes here ...

>>> s0 = S()  #  Empty scene instance.
>>> s1 = s0():
        ... change attributes for scene1 ...
>>> s2 = s0():
        ... change attributes for scene2 ...
>>> s1a = s1( "house", 27, 32 ):
        ... a derivative of scene1 ...
>>> s1a1 = s1a( "tree", 105, 12 ):
        ... a derivative of scent1a ...

Cloning an instance is just like instantiating a class, including the
ability to initialize with arguments.

Does this provide the basic functionality you need?

-- Dave




More information about the Python-list mailing list