IsPython really O-O?

Adam Spitz adamspitz at bigfoot.com
Wed Nov 14 15:13:08 EST 2001


Paul Prescod wrote:

> 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.

Um... sort of. It's really not as sneaky as you think. It's part of
the culture. We *expect* people to do things like that. We encourage
it. You're right, though, that the potential consequences are just as
bad in Ruby or Smalltalk. We just think that the advantages are worth
it, that's all.

Sometimes I'll be programming and I'll have a need for a certain
method on the Array class, but it's not there. Or I'll write a
string-manipulation method as part of another class, but then decide
that it really ought to live in the String class. In most other
languages, I feel a little twinge of annoyance. In Ruby or Smalltalk,
I just go add the method.

The biggest advantage by far, though, is that it encourages evolution.
When you've got lots and lots of programmers out there thinking up new
library methods and adding them and playing with them and tweaking
them, the best ones are going to get proposed as additions to the
standard library, and the standard library is going to get really
good. (Ever hear a Smalltalker brag about how the Smalltalk class
library is so amazing? Guess how it got that way.)

Anyway, because this *is* a cultural issue, adding this feature isn't
necessarily a good idea for Python. Your priorities are different, and
I wouldn't be surprised if you decided that the risks are too high.
(Maybe someone here could come up with a clever Python-ish way to get
the same effect with less risk.) But this is the sort of thing that
prevents me from embracing Python whole-heartedly.


Adam Spitz



More information about the Python-list mailing list