Accessors in Python (getters and setters)
Bruno Desthuilliers
onurb at xiludom.gro
Thu Jul 13 10:54:33 EDT 2006
mystilleef wrote:
> Bruno Desthuilliers wrote:
>
>>>>You choose a bad name for a *public* symbol.
>>>
>>>
>>>My point exactly! It doesn't solve my problem!
>>
>>What do you hope ? Something that cures cancer ? Please enlighten us and
>>explain how explicit getters/setters would have solved the problem of
>>badly named getters/setters ?
>>
>
> I did already. If I had used Java, Eiffel, Smalltalk or C++, I would
> have easily changed tmp to temporary_buffer
What I ask you is about renaming get_tmp/set_tmp to get_temporary_buffer
and set_temporary_buffer.
> without having search and
> replace or grep 27000 lines of code. The point of accessors in those
> languages is encapsulation.
Nope, the point of accessors (in the meaning of get_XXX/set_XXX *public*
methods) is to remedy the lack of support for computed attributes syntax
(ie accessing something like a public data member when it really go thru
implementation methods).
Encapsulation is about depending on an interface, not an implementation.
Your problem is really with interface change, not implementation change.
> Which means I can change any detail of
> implementation, yes including names of attributes, without breaking
> code.
I'm not asking about to rename an *implementation* attribute, but about
how to rename a pair of *API* badly named getter/setter.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list