Python's "only one way to do it" philosophy isn't good?

Steve Holden steve at holdenweb.com
Fri Jun 29 12:22:04 EDT 2007


Douglas Alan wrote:
> Michele Simionato <michele.simionato at gmail.com> writes:
> 
>>> I've written plenty of Python code that relied on destructors to
>>> deallocate resources, and the code always worked.
> 
>> You have been lucky:
> 
> No I haven't been lucky -- I just know what I'm doing.
> 
>> $ cat deallocating.py
>> import logging
>>
>> class C(object):
>>     def __init__(self):
>>         logging.warn('Allocating resource ...')
>>
>>     def __del__(self):
>>         logging.warn('De-allocating resource ...')
>>         print 'THIS IS NEVER REACHED!'
>>
>> if __name__ == '__main__':
>>     c = C()
>>
>> $ python deallocating.py
>> WARNING:root:Allocating resource ...
>> Exception exceptions.AttributeError: "'NoneType' object has no
>> attribute 'warn'" in <bound method C.__del__ of <__main__.C object at
>> 0xb7b9436c>> ignored
> 
> Right.  So?  I understand this issue completely and I code
> accordingly.
> 
>> Just because your experience has been positive, you should not
>> dismiss the opinion who have clearly more experience than you on
>> the subtilities of Python.
> 
> I don't dismiss their opinion at all.  All I've stated is that for my
> purposes I find that the refcounting semantics of Python to be useful,
> expressive, and dependable, and that I wouldn't like it one bit if
> they were removed from Python.
> 
> Those who claim that the refcounting semantics are not useful are the
> ones who are dismissing my experience.  (And the experience of
> zillions of other Python programmers who have happily been relying on
> them.)
> 
> |>oug

"Python" doesn't *have* any refcounting semantics. If you rely on the 
behavior of CPython's memory allocation and garbage collection you run 
the risk of producing programs that won't port tp Jython, or IronPython, 
or PyPy, or ...

This is a trade-off that many users *are* willing to make.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list