Python vs Java garbage collection?

Ganesan R rganesan at myrealbox.com
Mon Dec 23 07:03:08 EST 2002


>>>>> "Martin" == Martin v Löwis <martin at v.loewis.de> writes:

> However, it is also not surprising that people defend their
> programming practice to rely on the open(filename).read() pattern to
> DTRT: Nobody wants to be accused of being a sloppy programmer. If you
> add the facts of life to the facts of documentation, you see that
> there is really nothing wrong with such a programming practice - if
> you are aware of all the finer points.

I guess, that's really the key thing - _if_ you are aware of all the finer
points. This is assuming "int" is 32-bits in C. You know for in most current
hardware "int" is 32-bits, you know that "int" is 32-bits in most 64-bit C
implementations too. So there's really nothing "wrong" in that programming
practise.

However when you were programming in 16-bit DOS, it wouldn't have been a
good idea to assume 16-bits for an int even if you never intended to port
that program to 32-bit hardware. 32-bit hardware is out there and you never
know if somebody else wants that little program you wrote on that hardware.
That's why, FWIW, I tend to agree with Erik's point of view. 

This programming practice ought to deprecated _unless_ the programmer is
fully aware of what (s)he's doing. Take a module writer for example. He may
not care about Jython and choose to depend on the finalizer. Yes, Jython may
disappear tomorrow; but the fact is it's a reality today and there are many
users out there using Jython.  Our fictional module writer might have
rendered his module useless for Jython users today.

I code in Java, CPython and Jython and I _am_ frustrated by the lack of
destructors in Java/Jython. It's a pain to take care of everything in a
"finally" block while a simple destructor will do the job. However, Java
garbage collectors are a fact of life and it's not a good idea to make
simplifying assumptions.

I wish there were an equivalent of lexically scoped objects (auto objects in
C/C++) as opposed to references in Java/Python. At least, the language can
guarantee destruction for those objects. It won't simplify everything, but
at least I can use a simpler locking idiom :-).

-- 
Ganesan R




More information about the Python-list mailing list