does python have useless destructors?

Michael P. Soulier msoulier at digitaltorque.ca._nospam
Thu Jun 10 11:12:53 EDT 2004


On 10 Jun 2004 01:00:09 -0700, David Turner <dkturner at telkomsa.net> wrote:
> 
> I'd challenge you on all three of those.  Simple?  Not to the guy who
> has to remember to write finally around every resource-allocating
> operation that may raise an exception.  Clean?  Hardly.  See my
> example below.  Explicit?  Yes, that's true, it is explicit.  Much in
> the same way as malloc and free are explicit.  Are you sure that's
> what you want?

This is exactly what I've been arguing. I had one individual email me
privately and insult my opinion of elegance. Nice to know that usenet
hasn't changed much. I find the C++ code below far more elegant than the
explicit release. Exactly what is the point of encapsulation if I have
to look inside the black box?

> C++:
> ----
> mutex::scoped_lock lock(db_lock);
> updatedb();

I greatly prefer this. One of the things I hate about Perl is the fact
that I end up with "or die()" noise on every line that attempts to do
something. Python was so much cleaner in that I could just put all
suspect code in a try block. Now, it's looking like every time I acquire
something, I'll need a try/finally around it to make sure it's released.
I've traded one set of noise for another. Python programmers are always
claiming that Python is so much cleaner than most languages. Lately, I'm
not seeing that, and I think more can be done to achieve that.

Mike

-- 
Michael P. Soulier <msoulier at digitaltorque.ca>
The major advances in civilization are processes that all but wreck the
societies in which they occur.
-- Albert North Whitehead



More information about the Python-list mailing list