Friday, March 21, 2008

PyCon: Don't Call Us, We'll Call You: Callback Patterns and Idioms in Python

Don't Call Us, We'll Call You: Callback Patterns and Idioms in Python

This was a typical, high-quality, interesting talk by Alex Martelli.

Using the "key" argument of the "[].sort" function is far more efficient than using the "cmp" argument because the key only needs to be calculated once.

There are all sorts of uses for callbacks.

Callbacks come from a functional programming mindset.

The template method design pattern is more rigid than simply passing a callback. (2 points for Mike Cheponis if he's reading this.)

Callbacks can be used to customize a function's behavior.

Callbacks can be used for event handling.

Use "functools.partial(callable, *args, **kw)" for partial function application.

Twisted error callbacks are awesome.

No comments: