IsPython really O-O?

Paul Prescod paul at prescod.net
Tue Nov 13 22:21:09 CET 2001


Adam Spitz wrote:
> 
>...
> 
> 
> def MyClass_newMethod(self):
>   print "new method"
> MyClass.newMethod = MyClass_newMethod
> 
> I smiled just now when I realized that the Python version is actually
> fewer lines of code. :) But I still don't think it feels right. In
> Smalltalk and Ruby, I'm just using the standard mechanism for adding
> methods to a class. In Python, it feels like I'm sneakily hacking an
> extra method into a class against its will. (Does that make any sense?
> Maybe I'm being too touchy-feely. :)

You are doing something sneaky in *any* language because if anyone else
defines newMethod in any other module anywhere in the system you'll
overwrite each other. Classes are more or less global variables and so
are their methods. 

Python would probably not have first-class syntax to do this until there
were a way to do it that scaled well to large programs written by people
who do not necessarily communicate with each other.

 Paul Prescod




More information about the Python-list mailing list