should I put old or new style classes in my book?

Carl Banks pavlovevidence at gmail.com
Fri May 30 05:15:47 EDT 2008


On May 29, 12:07 pm, allendow... at gmail.com wrote:
> The current edition of the book presents old style classes.  I am
> considering
> switching to new style classes on the assumption that this should be
> the default
> choice for new programs.  The drawback is that a lot of the online
> documentation
> still uses old style classes.


New style, all the way.

The drawback you speak of for new-style classes I think is today more
of a drawback for old-style.  The problem is, when a newbie goes
looking for examples, there is a lot of code out there that uses
things like properties, type(instance), @staticmethods, and so on.
Those won't work, and will confuse the hell out of newbies, if you
teach them old-style.  OTOH, the examples out there that are written
for old-style usually still work for new-style classes.

The only significant issue, as far as I'm concerned, is the list of
bases.  Which is why, even if you only cover new-style classes, it's
important to at least mention that there used to exist old-style that
don't list any bases (in Python 2.x).  And then tell the user, "We're
not covering it, it's not something you need to worry about, and most
of the time you can and should add (object) and the code will still
work."  And leave it at that--let the interested newbie seek out more
information on their own.


Carl Banks



More information about the Python-list mailing list