[XML-SIG] foo.bar vs. foo.get_bar()

David Ascher da@ski.org
Thu, 4 Nov 1999 16:36:53 -0800 (PST)


On the topic of whether to do foo.bar or foo.get_bar(), I would like to
point out a cautionary tale.  When doing NumPy, Jim Hugunin chose the .foo
notation (as it happens, only for some attributes, not for all, for
reasons best left between Jim and his therapist <wink>). While that is
appealing, it had the problem in the NumPy world that it made subclassing
from his array type quite difficult. While having a __[g|s]etattr__
mechanism is fine for a Python 'expert', it is not something that one
should force users to use if they wish to subclass from a given class.  It
is too easy to screw up and get stack overflows. 

In other words, *if subclassing is an issue for the class under
discussion* if you use the .foo notation, make sure to have default
__getattr__ hooks which would call the get_foo() hooks, so that the user
can just define those get/set functions which she needs to.

--david