Python vs Java garbage collection?

François Pinard pinard at iro.umontreal.ca
Tue Dec 24 12:58:44 EST 2002


[Stuart D. Gathman]

> The problem with Python reference counting, is that it encourages sloppy
> programming like:

>   data = open('myfile','r').read()

There is no sloppiness there.  The only nit one could have against the above
line is that `file' is now a better writing than `open'.  Let's use it:

    data = file('myfile','r').read()

This is clear, legible, elegant, and all functional in CPython.

> [...] The proper code:

>   fp = open('myfile','r')
>   data = fp.read()
>   fp.close()

> is not as pretty.

This code is surely proper in Jython, working around the fact that Jython
relies on Java's garbage collector.  For CPython, it is probably less
proper, because it is more cumbersome and less legible.  For me, more
legible it is, more Python it is.  Like it or not, Jython is a tiny bit less
Python than CPython! :-)

Of course, one may ought to use Jython for various reasons, and Jython is
undoubtedly a wonderful blessing whenever you need it.  But this is the
choice of a programmer to write his code whether with Jython in mind or not.
The key point is that there is nothing sloppy in choosing the `not' side.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list