Metaclasses?

Quinn Dunkan quinn at hedono.ugcs.caltech.edu
Wed Apr 26 00:23:01 CEST 2000


On Tue, 25 Apr 2000 21:40:16 +0200, Robb Shecter <shecter at darmstadt.gmd.de>
wrote:
>Hi,
>
>I read an old post about metaclasses (included on the cd-rom with the
>book "Mit Python programmieren"), and got very interested, because I
>imagine that by making a new metaclass, I could maybe fix the one thing
>about Python that annoys me: the obligatory use of "self" in method
>declarations and variable access.  (Python's syntax is so clean and neat
>in all other areas, I feel like it's a shame that there's excess
>verbosity in this one place.)
>
>So - are metaclasses just a random idea, or is there something in the
>works?

Metaclasses have been implemented for a long time, see
src/Python-x.y.z/Demo/metaclasses.  I don't think many people use them,
presumably because they like neat and clean, and metaclasses, while clever,
are not (shall we say) conducive to clarity of understanding.

Python's syntax has "excess" verbosity in *many* places (that's a feature),
but self.foo is not one of them.  In python, you *always* access the attribute
of an object with obj.attr  Some people don't like this, and there have been
threads in the past about it, but other people think "more verbosity and less
magic" is more pythonic than "less verbosity and more magic".

Anyway, even if you could figure out the ambiguity problem, I don't think
metaclasses would help you, bytecodehacks might.  Or you could just grit your
teeth, type five extra characters, and as a bonus get something that can be
read by other people.  You could shorten those five chars further by writing a
macro or abbr for your editor.



More information about the Python-list mailing list