Python 2.0

Gordon McMillan gmcm at hypernet.com
Tue Jun 1 11:01:43 EDT 1999


Yukihiro Matsumoto wrote:
> 
> "Vadim Chugunov" <chega_ at yahoo.com> writes:

> |I'm sorry for being unclear, but the key words here were: "to free up
> |resources".
> |And I meant "to free up resources the moment I expect them to", not "some time
> |later".
> 
> Well, OK.  I understand now.  Now only thing I can say is, why do
> you emphasize so much on reclaiming object at the time you exepcted?

As someone used to GC, you would probably never write:

 txt = open('blahbalh.txt','r').read()

This is a common idiom for those of us used to ref counting.
You would certainly take a reference to the file object so you could 
explicitly close it. 

On the other hand, you don't worry about circular references, while 
we train ourselves to recognize them and take corrective action.

> Because of your C++ background?

Ironically, C++ can beat the pants off anything else in this regard. 
With smart pointers, you can handle ref counts automatically, even 
when there are circular references.  And since you have the choice 
between heap and stack, you can be absolutely certain that you 
release resources, even when an exception is thrown.

> |BTW, this is a common expectation from anyone coming from a C++ background.
> |In C++, deallocation in destructors is the only way you can use exceptions
> |without leaking resources.
> 
> Yes, but it's not true for HIGHER languages like Python or Java (or
> Ruby).

In this regard, they're a step backwards.

- Gordon




More information about the Python-list mailing list