On Jun 17, 2009, at 9:43 PM, Steven D'Aprano wrote:
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.
Memory management may be an "implementation detail", but it is
unfortunately one that illustrates the so-called law of leaky
abstractions. So I think that one has to write code that follows the
memory management scheme of whatever language one uses. For code
written for CPython only, as mine is, RAII is an appropriate idiom and
not kludgy at all. Under your assumptions, its use would be wrong, of
course.
Charles Yeomans
--
http://mail.python.org/mailman/listinfo/python-list