function pointers

Alex Martelli aleaxit at yahoo.com
Fri Apr 27 04:46:29 EDT 2001


"Courageous" <jkraska1 at san.rr.com> wrote in message
news:90bhetcu10kn5otresb1dq65pps2vha6ii at 4ax.com...
>
> >Indeed, being able to move around bound methods is one of the things
> >that impressed me most about Python.
>
> Yup. And for those of you not following the Evil Empire (tm),
> C-sharp has an analogous structure called a "delegate".

I think it's more of a Hejlsberg "trademark" -- he put it
in Delphi when he architected that for Borland, then he
moved to MS and put it in MS's version of Java (and made
it a cornerstone of the WFC framework), and now in C#.

> This is an answer to the whole static-member-function-
> dispatch-to-non-static-member-function lunacy that crept
> into C++ as callbacks grew into favor. And it beats the hell
> out of those spurious lunatical functor objects as well. :)

I don't really share your (and Hejlsberg's:-) enthusiasm
for 'delegates' (and strongly dislike the NAME 'delegate'
for this purpose, but that's another issue); first class
callables ARE nice, but, in a Java-ish framework, it has
always seemed to me that interfaces plus inner classes
met that need pretty well.  (In C++, you run smack into
lack of garbage collection for this as for many other
potential idioms, of course -- so you roll your own RC
or whatever, etc, etc -- can you spell "boilerplate"?-).

Bound methods *AND* other more-generally curried functions
are definitely alternatives to using objects/interfaces/
classes for this purpose, of course.  I do like having
the choice in Python, particularly because its general
signature-based polymorphism means I can pass bound methods
when they will suffice and other kinds of callables where
I need more generality.  In a language that is statically
type-checked at runtime, I suspect that interfaces' better
generality makes them preferable to "bound-methods" (given
that no other currying is directly supported).


Alex






More information about the Python-list mailing list