A java hobbyist programmer learning python

TheFlyingDutchman zzbbaadd at aol.com
Sun Jan 25 21:04:59 EST 2009


>         If you're building an extension tree, you'll either have to supply
> layers of getter/setter methods, or hand-mangle references to attributes
> defined in the superclass.
>
>         Say you start with a "Point2D" class, and make the X, Y coordinates
> double underscore.
>
>         Now extend it to a "Point3D" class via inheritance. The 3D class
> will not be able to access (set) the X, Y values without a setter method
> defined in the parent OR by unmangling the parent names.
>
>         If you'd used the common convention of single underscore as "don't
> touch if you're an outsider", the 3D extension can be considered an
> insider and directly access the X, Y
>
>         Which would you rather read in a 3D point class derived by extending
> a 2D point?
>
>         def move(self, xmod, ymod, zmod):
>                 self._z += zmod
>                 self._y += ymod
>                 self._x += xmod
>
> or
>
>         def move(self, xmod, ymod, zmod):
>                 super(Point3D, self).move(xmod, ymod)
>                 self._z += zmod
>
> or
>
>         def move(self, xmod, ymod, zmod):
>                 self._Point2D__x += xmod
>                 self._Point2D__y += ymod
>                 self.__z += zmod
>
>         Speaking for myself, I'd prefer the first
> --
>         Wulfraed        Dennis Lee Bieber               KD6MOG
>         wlfr... at ix.netcom.com         wulfr... at bestiaria.com
>                 HTTP://wlfraed.home.netcom.com/
>         (Bestiaria Support Staff:               web-a... at bestiaria.com)
>                 HTTP://www.bestiaria.com/

I like the latter two styles, particularly the last one. That way you
can see at a glance that those member variables are defined in the
super class. But then I am a fan of Hungarian notation, which many
programmers can't stand.



More information about the Python-list mailing list