function pointers

Erik Max Francis max at alcyone.com
Thu Apr 26 11:39:05 EDT 2001


Courageous wrote:

> Not only does it have function pointer equivalents, it does things
> that even
> C, C++, and Java can't. For example:
> 
> >>> class MyClass:
>         def f(self):
>                 print "amazing"
> 
> 
> >>> m = MyClass()
> >>> f = m.f
> >>> f()
> amazing
> >>>
> 
> You can't do that in C++ or Java!
> 
> It's very cool.

Indeed, being able to move around bound methods is one of the things
that impressed me most about Python.  Often you want a simple callback
mechanism, but if you're fiddling with methods and can only shuffle
around references to unbound methods, this makes things less pleasant. 
Guido either had the foresight or experience (or both) to realize that
bound methods are fantastically useful -- they're something that
language writers tend to realize would be a great addition ... too late.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Love is the wisdom of the fool and the folly of the wise.
\__/ Samuel Johnson
    blackgirl international / http://www.blackgirl.org/
 The Internet resource for black women.



More information about the Python-list mailing list