[XML-SIG] foo.bar vs. foo.get_bar()
Jack Jansen
jack@oratrix.nl
Fri, 05 Nov 1999 11:44:23 +0100
> 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.
Ah, that's a good one. Maybe we should put the foo.bar functionality in a
mixin class, and caution people only to include this mixin at the highest
level in their class hierarchy?
There's also something in the foo.bar scheme that will bite even experts.
Let's assume I have a class representing something with an xml-attribute bar,
and I need to create a subclass that shows the same attribute bar but somehow
modified (converted to all upper case, for instance). Something like
class Super(Base):
def get_bar(self):
return string.toupper(Base.get_bar(self))
will work fine, but I can't think of how to do this with the foo.bar access
scheme.
On the other hand, maybe this isn't a problem because I shouldn't try to do
this with subclassing but with wrapper classes.
--
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm