does python have useless destructors?

David Turner dkturner at telkomsa.net
Fri Jun 11 22:44:38 CEST 2004


tfb+google at tfeb.org (Tim Bradshaw) wrote in message news:<fbc0f5d1.0406110524.3e44c422 at posting.google.com>...
> dkturner at telkomsa.net (David Turner) wrote in message news:<e251b7ba.0406100011.39a795e1 at posting.google.com>...
> >
> > This makes me sad.  But there is some hope in the following pattern,
> > although it can be quite awkward:
> > 
> > def with_file(fname, mode, oper):
> >     f = open(fname, mode);
> >     try:
> >         oper()
> >     finally:
> >         f.close()
> > 
> > Of course, this can very quickly turn your code into so much
> > functional goo.  That's not necessarily a bad thing, as Lisp
> > programmers can attest...  But it's still not quite as powerful as
> > RAII.
> 
> No Lisp programmer worth their salt would tolerate such a horror.  In
> the specific case above there's already an idiom for doing this in
> Common Lisp:

Actually I was thinking more of the open() function than with the
with_file() function when I said "functional goo" :-).

It's really quite funny that Lisp doesn't suffer much from this sort
of problem.  You'd think we'd learn...

Regards
David Turner



More information about the Python-list mailing list