Accessors in Python (getters and setters)

Antoon Pardon apardon at forel.vub.ac.be
Thu Jul 13 08:48:36 EDT 2006


On 2006-07-13, mystilleef <mystilleef at gmail.com> wrote:
>
>> 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 without having search and
> replace or grep 27000 lines of code. The point of accessors in those
> languages is encapsulation. Which means I can change any detail of
> implementation, yes including names of attributes, without breaking
> code.

Well the impression we have is that should you used Jave, Eiffel, ...
You would not only have had an attribute tmp but would have had
accessores like getTmp and setTmp.

Now if you find tmp do be a bad name, it seems this would
imply that getTmp and setTmp are equally bad names. So if you
are using Java, Eiffel, ... and you want to get rid of the
bad names, it seems you have to search and replave 27000 lines
of code. You will just be replacing getTmp into getTemporary_buffer
and setTmp into setTemporary_buffer instead of just tmp into
temporary_buffer.

You seem to argue that all you had to do was change the attribute
tmp and then only needed to change the code of the class. But
what we are wondering about is why you would find tmp such a bad
name that you want to change it all over the program but
would be willing to leave names like getTmp setTmp.

So why is tmp bad in code like:

  obj.tmp = f()

But is setTmp ok in code like:

  obj.setTmp(f())

-- 
Antoon Pardon



More information about the Python-list mailing list