Class design: accessing "private" members

Steve Holden sholden at holdenweb.com
Sun Apr 8 00:03:10 EDT 2001


"Steven D. Arnold" <stevena at neosynapse.net> wrote in message
news:mailman.986695793.20923.python-list at python.org...
> <html>
> At 02:15 PM 6/30/2000 +0200, Jerome Quelin wrote:
> Then, is it better/cleaner to access private members with accessors or
not?
> Is it a matter of style? Or are there hidden caveheats using (or not
using)
> accessors? It _seems_ cleaner to use accessors, but man, it's quite
awkward.

[ Discsussion of "properties" vs."attributes" overlooked]

> Having said all that, I admit a little hypocrisy: in short scripts on
> rare occasions, I do not use accessors. Sometimes they're more
> trouble than this script is worth. However, beware of that sort of
> thinking. Little throwaway scripts very often end up hanging around
> a long time and it's good to craft every line of code carefully with
> that in mind.

This is sound practice, but a Pythonic liberty has always given the
intelligent programmer enough rope to shoot themselves in the foot, if
you'll forgive a little metaphor-mixing.

In otehr words, Python allows you to do it either way. If you don't know
enough to discriminate between the cases when it's a bad idea and the cases
when it's a good idea then you should just be grateful you found Python
before someone wrapped you in the C++/Java straitjacket.

although-straitjackets-aren't-entirely-bad-thngs-and-can-improve-the-lives-o
f-mad-wearers-ly y'rs  - steve









More information about the Python-list mailing list