does python have useless destructors?

Michael Hudson mwh at python.net
Fri Jun 18 06:29:47 EDT 2004


Donn Cave <donn at u.washington.edu> writes:

> In article <m3hdtam7z0.fsf at pc150.maths.bris.ac.uk>,
>  Michael Hudson <mwh at python.net> wrote:
> 
> > Donn Cave <donn at u.washington.edu> writes:
> > 
> > > In article <m3k6y6o8cd.fsf at pc150.maths.bris.ac.uk>,
> > >  Michael Hudson <mwh at python.net> wrote:
> > > > Donn Cave <donn at u.washington.edu> writes:
> > > > > In article <m3fz8xozi1.fsf at pc150.maths.bris.ac.uk>,
> > > > >  Michael Hudson <mwh at python.net> wrote:
> > > > > > I would urge everyone participating in this thread to read PEP 310,
> > > > > > the email conversation linked therein and (optional) *understand* it.
> > > > > 
> > > > > It seems to be superficially similar to finalization, 
> > > > 
> > > > OK, I've found this thread pretty hard to follow.  What is
> > > > "finalization" in context?
> > > 
> > > Operational definition would be `call __del__ or its C equivalent',
> > > at the effective end of the object's lifetime.
> > 
> > OK.  I claim you can't really have that, and that you don't really
> > need it anyway.  The idea behind PEP 310 is to acheive the ends of
> > RAII in C++ by different means.
> > 
> > What else do you want to use __del__ methods for?
> 
> That would be my question.  That's what __del__ methods _are_
> used for.  C Python users _do_ really have that, it just takes
> more care than we like if it needs to be 100% reliable.

Now you've lost me.

What did the last __del__ method you wrote do?

> Maybe I don't need it, maybe 310 gives me RAII and that's what
> I really need.  I don't know, but again, 310 doesn't give me
> anything of consequence in terms of software architecture.

Indeed.  It's sole aim is to make doing the right thing a bit less
painful.  One of the nice things about e.g. Python's exception
handling is that it makes doing the right thing *easier* than doing
the wrong thing -- no forgetting to check return codes and so on.  I
don't see a way of making using a 'with:' block *easier* than not, but
I contend it's an improvement.

Cheers,
mwh

-- 
  <PenguinOfDoom> I reject that approach. It has a suspicious lack
                  of internet.                  -- from Twisted.Quotes



More information about the Python-list mailing list