[Python-Dev] metaclass insanity

Guido van Rossum guido@python.org
Mon, 04 Nov 2002 20:56:33 -0500

> If I write a container it seems reasonable to nest its iterator class.

There are lots of situations where you need helper classes.  It's been
an established style among most Python developers for many years to
place these in the same module as the "main" class.  Nesting them
inside other classes has few advantages -- it's disruptive for the
reader of the main class (often the helpers are "details" whose
understanding can be easily put off) and it doesn't work very well
(e.g. can't be pickled).

> > This sounds unpythonic, and confirms my expectation that this is an
> > example of trying to write C++ in any language. :-)
> A latent hatred of C++ sure do come in handy if'n there's an idea we
> don't like floatin' around, don't it? 

Well, you acted as the straight man by bringing up C++. :-)

I was expecting examples from the Java world, where there's no
distinction between classes and modules, and hence classes become the
unit of packaging.

> If we define "Pythonic" narrowly enough, we can make sure it never
> grows up to be another one of those `multiparadigm' programming
> languages.

Class nesting just hasn't been observed much among Python programmers,
and I don't think it's the best solution for the problem that is
brought up as a reason to do it.

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