Guido experimenting with generic functions, TG using them

Apr 10, 2006 19:59 · 204 words · 1 minute read

Guido has blogged about a generic function implementation (he uses the term Dynamic Function Overloading) that he has checked into the Python sandbox. It is good news to see work on this going into the core of Python. TurboGears 0.9 makes heavy use of Phillip Eby’s RuleDispatch package and it gives a lot of power in choosing an error handler, choosing an output format and even determining if a user is authorized for a resource, if you use a new package created by Alberto. We’re using it quite a bit behind the scenes and strategically exposing it here and there. If this becomes a standard part of Python, we don’t have to worry about people not understanding how the implementation works. Most excellent.

Update: in the comments, Bob Ippolito points out that Guido’s code is just doing dispatch by type and not by expression, as RuleDispatch does. I had noticed this originally, but tuned it out when I was posting. RuleDispatch is exceedingly powerful because of the way it handles expressions. What Guido describes is certainly a useful addition to Python and give people a chance to get used to functions being chosen at runtime, which will lessen the barriers to folks using RuleDispatch.