does python have useless destructors?
David Turner
dkturner at telkomsa.net
Mon Jun 21 06:40:42 EDT 2004
Michael Hudson <mwh at python.net> wrote in message news:<m3zn71kvbm.fsf at pc150.maths.bris.ac.uk>...
> dkturner at telkomsa.net (David Turner) writes:
>
> [snippety]
>
> > We have three issues here - garbage collection (undoubtedly more
> > efficient than reference counting), RAII (undoubtedly safer than
> > try/finally), and PEP 310 (the "with" form).
>
> I fail to buy either of your 'undoubtedly's. You may be correct in
> both of them, but they both require justification...
>
> (Besides, saying garbage collection is more efficient than reference
> counting is like saying fruit is more tasty than apples).
>
> > I've already pointed out the problems with "with" (it's the same ball
> > game as try/finally, and suffers from the same limitations).
>
> I must have missed that. Message-ID?
For your convenience, I've summarized my arguments (briefly) in a
posting here:
http://dkturner.blogspot.com/2004/06/garbage-collection-raii-and-using.html
(Something I didn't mention: reference counting involves atomic
increments and decrements which can be expensive).
> > So my opinion is that the RAII idiom should somehow be enabled in
> > Python. The crucial difference between "with" and RAII here is that
> > "with" requires intervention by the end-user of the object, whereas
> > the RAII idiom does not.
>
> Well, in C++ the distincton the creator of the object makes is that
> the RAIIed thing is an automatic variable, isn't it?
Not necessarily. You can usefully have a shared (reference-counted)
pointer to an RAII object. In fact, this is more generally useful
than an automatic variable, if more expensive (it's a cover for the
auto variable concept). But I do agree that C++'s auto variables led
directly to the development of RAII, which might otherwise have been
missed.
Regards
David Turner
More information about the Python-list
mailing list