Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Jun 17 21:43:37 EDT 2009


On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote:

>> Even CPython doesn't rely completely on reference counting (it has a
>> fallback gc for cyclic garbage).  Python introduced the "with"
>> statement to get away from the kludgy CPython programmer practice of
>> opening files and relying on the file being closed when the last
>> reference went out of scope.
> 
> I'm curious as you why you consider this practice to be kludgy; my
> experience with RAII is pretty good.

Because it encourages harmful laziness. Laziness is only a virtue when it 
leads to good code for little effort, but in this case, it leads to non-
portable code. Worse, if your data structures include cycles, it also 
leads to resource leaks.



-- 
Steven



More information about the Python-list mailing list