Classes: Old or New and How?

Jeff Shannon jeff at ccvcorp.com
Tue Apr 23 14:04:21 EDT 2002


In article <aa2sh6$2o7v$1 at ulysses.noc.ntua.gr>, 
rs96057 at hotmail.com says...
> 
> "Philip Swartzleonard" <starx at pacbell.net> wrote in message
> news:Xns91F8BDF3CF983RASXnewsDFE1 at 130.133.1.4...
> > [...] When i start a class like
> > this, should I bother explicetly deriving from Object, or should I set
> > that flag that makes everything like that, or should I just not bother?
>
> I think that, new style is some kind of an extension of the old one and that
> in later versions of Python the default style will change to the new (maybe
> a unified one).

Yes, the intent of new-style classes is that they will be the 
default in a future version of Python.  The reason behind the 
change is so that classes can be unified with types.  The 
question at hand is, whether during this transitional period, it 
makes sense to make an effort to use the new style, or to simply 
keep using the old (and still default) style.

I would say that it depends upon two things -- if the subtle 
differences in behavior work for or against your intent for the 
class, then it makes the most sense to use whichever style is 
most suited.  Of course, the vast majority of trivial classes, it 
won't make any difference.

In those cases, I'd look at the probable lifetime of the code.  
If you think you might still be using it when the next version of 
Python comes out, you're probably best to use new-style classes 
wherever practical.  That way, when new-style becomes the 
default, you won't get any nasty surprises, because you'll have 
been coding to that for some time, and any effect that the change 
would have, will already have been accounted for.  If you're 
writing throwaway code, though, then it doesn't matter, and you 
might as well use the default old-style classes.

Of course, it might not be a bad idea to try to use new-style for 
everything (except where it breaks code), so that you'll be 
thoroughly used to the semantic differences when it *does* become 
the default...

(Spoken as someone who's still using Python 2.1 ...)

-- 

Jeff Shannon
Technician/Programmer
Credit International



More information about the Python-list mailing list