Prothon Prototypes vs Python Classes

has has.temp2 at virgin.net
Sun Mar 28 19:28:47 CEST 2004


David MacQuigg wrote:
>> Is all this complexity unecessary?

Yup. Scary to realise a good chunk of your hard-won expert knowledge
is essentially worthless make-work, eh? Ah well... c'est la vie. <g>


Joe Mason replied:

>Complexity's ok if it's in the right place

Hmmm... sort of true. However:

1. Complexity is _never_ desireable. (Unless you're deliberately
obfuscating code, which is the exception that proves the rule.)

2. Essential complexity is something you have to accept; in any large
system it's almost inevitable. Hiding this from casual view may a
reasonable compromise in preventing the average user's head from
exploding.

3. Gratuitous complexity should be eliminated at every opportunity,
however. Hiding it is just a kludge and a copout.

4. Often what's seen as essential complexity is actually gratuitous
complexity that nobody's noticed. (Or have noticed, but prefer to keep
schtum about it for whatever reasons of their own.)



> Ed Suominen just posted a situation where classes and instances need to
> be treated separately.
[...]
> So here's one point where the simplification of prototypes actually ends
> up making the user code more complicated than the full Python version.

Not at all. All it shows is that a class-based programming style
doesn't work well in a classless language. Here's a more sensible
solution:

# 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.

To a class-based programmer, prototype-based OO must feel rather like
running down the High Street with no pants on; a wonderfully
liberating experience once you get over the initial embarrassment.
Python's layering of a stiff, complicated, class-oriented programming
model atop such a highly dynamic implementation seems a bit perverse,
as well as a badly missed opportunity. (Needless to say, I'll be
watching Prothon's development with some considerable interest.:)


> But someone else said that prototype-based languages "tend to grow 
> features that mimic class-based ones", or soemthing like that.

One suspects, however, that such languages were getting along just
fine by themselves till the class-based programmers arrived. As with
missionaries, any approaching Java programmers should be shot on sight
or you'll be infested by crappy typesystems and worshipping bloody
generics before you know it. :p

has



More information about the Python-list mailing list