[XML-SIG] Re: XML-SIG digest, Vol 1 #392 - 11 msgs
Greg Stein
gstein@lyra.org
Wed, 3 Nov 1999 18:47:49 -0800 (PST)
On Wed, 3 Nov 1999, Thomas B. Passin wrote:
> Pure object-orented folks want node.getParent() instead of node.parent so
> the caller is not messing with the internals of the called object itself. A
> redesign could totally change the way in which getParent() works without
> changing the call at all, which is desirable.
That is an incorrect generalization.
I'm a "pure object-oriented" person and I prefer node.parent.
Object-orientation does not mean use a method for everything. It can
certainly mean that well-defined attributes are available for objects'
clients.
Further, the Python way of doing things is to expose the attributes. It is
not considered an "internal" of the object, but part of the object's
defined API. And the phrase "we're all adults" is well-used in this
context, too -- if the attribute is internal, then don't screw with it.
[ good Python design usually signals "internal" attributes with a leading
underscore ]
> In Python, is it possible and efficient to redefine node.getParent() to
> simply return node.parent? If so, you could have the benefits of both ways.
No. A function/method call is nowhere near as efficient as an attribute
access. Note that you example of node.getParent is *both* an attribute
access and a function all. 1) get the value of node.getParent (a bound
method in this case), then 2) call the resulting object with no params.
In other words, you can make the function calls in Python as fast as you'd
like, but you'll never hit zero-time, so func calls will always be slower.
Part of the Python programming gestalt :-)
Cheers,
-g
--
Greg Stein, http://www.lyra.org/