Defining accessor methods

Graham Ashton graham at
Tue Jun 26 05:36:49 EDT 2001

In article <3B37FED8.2DBA3AC2 at>, "Greg Ewing"
<greg at> wrote:

> Graham Ashton wrote:
>> I thought of having get_my_attribute() and set_my_attribute() but I
>> don't really like the idea because it just makes code that uses them
>> more (unnecessarily) long winded, and the author of the above URL
>> advises against it (though they don't say why).
> They're talking about Smalltalk, and in that context it *is*
> unnecessarily long-winded to include 'get' and 'set' in the method
> names.

I've had some very interesting replies to this thread, thanks to all who
responded. In short, accessor methods don't appear to be all that popular,
and there appear to be some good reasons why not, not least the
__setattr__ and __getattr__ methods. I've just thrown away all my accessor
methods and am going to have to repair rakes of code, but I must admit
that things are looking cleaner already.

> My experience suggests that, for internal code, it's usually easier not
> to bother with accessor methods until a clear need for them arises. But,
> as they say, your kilometerage may vary.

Indeed. It's interesting how learning a new language changes your outlook
on these issues on the fly...


More information about the Python-list mailing list