does python have useless destructors?

Michael Hudson mwh at python.net
Fri Jun 18 06:35:26 EDT 2004


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?

> 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?

> One possibility is to introduce scoped objects, analogous to auto or
> stack-allocated objects.  It would be illegal

How do you tell that this has/is going to happen?  If you can't pass
one of these objects to a subroutine, the idea is nearly useless, I'd
have thought.

> to pass a reference to these outside of a given scope, and they
> would have __del__ (or another method) called when the scope ends.
> This is slightly cheaper than reference counting, but of course it
> imposes very real limitations on the usefulness of the object.

Ah :-)

Cheers,
mwh

-- 
  > So what does "abc" / "ab" equal?
  cheese
         -- Steve Holden defends obscure semantics on comp.lang.python



More information about the Python-list mailing list