any ways to judge whether an object is initilized or not in a class

Alex Martelli aleax at mac.com
Tue Mar 20 11:27:07 EDT 2007


Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> wrote:
   ...
> There are plenty of reasons for preferring new style classes. If those
> reasons hold for you, then of course you should use new style classes.
> 
> But that's not the same thing as saying that you should use new style
> classes *even when you don't care about those features*.

You should always use new-style classes in order to avoid having to stop
and make a decision each time you code a class -- having to stop and ask
yourself "do I need any of the many extra features of new-style classes
here, or will legacy classes suffice?" each and every time.

There should ideally be only one obvious way -- and that obvious way is
to always use new-style classes and avoid a feature that's there only
for backwards compatibility with legacy code.

It's a specific case of the general rule "adopt good habits as
routines"; I recommend Limoncelli's excellent treatment of that subject
in his "Time Management for System Administrators" book.  By not having
to ask yourself "do I really need to do X" each and every time, but
making it an absolute and invariant habit to always do it, as long as X
is a good habit (will be useful some of the time and not damaging the
rest of the time), you save yourself time-waste, aggravation, and
useless expenditure of attention and mental energy.

> What I predict is that under the hood, Python 3 will complete the job of
> unifying types and classes. The distinction between classic classes and
> new style classes will go away. All classes will behave the same, whether
> you write "class X:" or "class X():" or "class X(object):" or whatever
> syntax Python 3 uses for defining classes.

Sure -- all the semantical peculiarity of legacy classes will disappear
(and won't be missed).  But meanwhile, no reason not to adopt good
habits.


Alex



More information about the Python-list mailing list