[Python-Dev] metaclass insanity

Guido van Rossum guido@python.org
Tue, 05 Nov 2002 12:00:45 -0500

> Keeping a definition of some X (whether X is a class, a function,
> whatever) as local as feasible has one obvious merit which I have
> already pointed out: a reader of the code need NOT ask himself
> "where is this X defined" when X is used, nor "how is this X used"
> when X is defined -- the answers become immediately obvious by the
> very way the code is structure... X is defined right here and used
> right here.

Yes.  However this is counterbalanced by the distraction for the
reader though when the details of X's implementation make it even a
moderately large lump of code (above a couple of lines); usually these
details aren't of immediate interest to the reader where X is used.

> > I also think that it's better that the iterator class *is*
> > accessible to the user -- that way you can do an isinstance()
> > check for it, for example.
> To me, that's a good reason to AVOID making the class directly
> accessible to the user.  I find that most uses that programmers
> make of type-testing in Python (e.g. with isinstance) are more
> damaging than helpful; anything that happens to discourage such
> damaging practices therefore looks good to me thereby.

So use a name starting with an underscore.  That's enough of a hint.

> In my experience so far, I find that wrapper classes tend to
> be rather small -- maybe that comes from my general style.

Wrapper classes are just one example of helper classes.  The argument
for keeping helper classes out of the way applies broadly.

--Guido van Rossum (home page: http://www.python.org/~guido/)