accessor/mutator functions

D

Dan Sommers

However in python, there is no harm in accessing the attributes
directly. You can change the implementation whenever you like, and
change the attributes into property()s and the users will never know.

[ ... ]
Read only attributes are easy to understand, unlikely to go wrong and
faster than getBlah() accessor methods.
Writable attributes I think are good candidates for methods though.
Looking inside an object is one thing but changing its internal state
is another and should probably be done through a defined interface.

I wish I'd said it that well in the first place myself. :)

Regards,
Dan
 
N

Nick Craig-Wood

Dan Sommers said:
We used to have holy wars over the appropriate level of comments in
source code.

Well according to the refactoring book I just read (by Martin Fowler)
the appropriate level of comments is None. If you see a comment you
should extract the complicated code into a method with a useful name,
or add well named intermediate variables, or add an assertion.

Its a point of view... Not 100% sure I agree with it but I see where
he is coming from. I like a doc-string per public method so pydoc
looks nice myself...
 
C

Carl Banks

Steve said:
Well, they are surely helpful in delegation contexts as well, or do I
misunderstand?

I consider that a degenerate form of constructing a name at run time.
:)

You're right: I should have said, "Don't use them unless you don't know
the name at programming time."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,221
Messages
2,571,134
Members
47,748
Latest member
LyleMondra

Latest Threads

Top