is python Object oriented??

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Feb 4 13:57:55 EST 2009


En Wed, 04 Feb 2009 07:05:22 -0200, Bruno Desthuilliers  
<bruno.42.desthuilliers at websiteburo.invalid> escribió:
> Gabriel Genellina a écrit :
>> En Mon, 02 Feb 2009 19:51:11 -0200, Russ P. <Russ.Paielli at gmail.com>  
>> escribió:
>>
>>> Suppose a library developer (or a module developer on a large team)
>>> uses leading underscores. Now suppose that, for whatever reason
>>> (pressure from the users, perhaps), the library developer decides to
>>> change a "private" attribute to public. Now all occurrences of the
>>> identifier need to be changed. If an assignment to the previously
>>> "private" attribute is missed, no warning will be issued (because
>>> Python allows new attributes to be added anywhere, even completely
>>> outside the class definition itself). And if the library is widely
>>> used, the probability of such bugs occurring is very high.
>>  So _foo becomes foo. Then:
>>  class X(object):
>>     def get_foo(self): return self._foo
>>     def set_foo(self, value): self._foo = value
>>     foo = property(get_foo, set_foo)
>
>
> FWIW, if there's no other need for the property, I'd do it the other way  
> round : directly make foo a plain attribute, and add a _foo property  
> whose accessors would raise a deprecation warning. Then there's no  
> chance I miss a an assignement to _foo !-)

Yes, that would be better. In any case, one has both static analysis tools  
(e.g. pylint) and dynamic warnings (like you said above) so I don't see a  
problem here.

-- 
Gabriel Genellina




More information about the Python-list mailing list