[Edu-sig] Gutless classes

Scott David Daniels Scott.Daniels at Acm.Org
Sat Sep 10 16:44:00 CEST 2005

Dethe Elza wrote:
   <lots of reasonable stuff on trampolining>
> class MyTrampolinedThing(object):
>     ...
>     def doYourThing(self, x,y,z):
>         klas = self.__class__
>         if isThisAMac():
>             klas.doYourThing = klas._doMacThing
>         elif isThisWindows():
>             klas.doYourThing = klas._doWindowsThing
>         elif isThisLinux():
>             klas.doYourThing = klas._doLinuxThing

_but_, I have a problem with the next three lines:
>         del klas._doMacThing
>         del klas._doWindowsThing
>         del klas._doLinuxThing

There is no reason to destroy the source of the method,
nor even the other (presumably unused) methods.  The Pythonic
way is to leave them alone with the underscores in front, and
expect programmers not to use them.

>         return self.doYourThing(x,y,z)

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Edu-sig mailing list