With PyCon just a few weeks away, I’ve been throwing together my slides for the presentation on generic functions, and I’m short a few examples and diagrams. The tricky part is that you can’t fit much text on a slide, so I need to come up with some nice pithy example uses of generic functions.
Well, actually, there are two tricky parts. One is that the examples need to be short, but the really tricky part is that they need to be pretty self-explanatory. Most of my real-life uses for generic functions take a bit too much explaining (e.g. command-line options, security rules, etc.). But I suppose they’re still a bit better than the “interactive fiction” examples I posted here previously.
Maybe I could also steal some ideas from SanFrancisco Design Patterns, which has some patterns like Key/Keyable and Keyed Attribute Retrieval that could be easily implemented with generic functions or rule dispatchers. (That book, by the way, was what first got me interested in rule-based dispatch systems. Its proposed implementations were very clunky and not at all agile, though, so when I came across predicate dispatch I knew it was a better approach.)
I probably also need some visual aides just to break up the reams of text on my slides, though. I had been thinking I’d write a tool to output a generic function’s internal decision tree as a GraphViz chart, but there are still some refactorings I’d have to do first that I probably won’t have time for. So, I may have to just make up a chart manually. But that really only means one illustration, out of maybe 30 slides. Maybe if I colorize the Python code on the code samples, it’ll make them look different enough to break up the monotony. 🙂
What do you think? Have you got any ideas for uses or examples you’d like to see?
I think it’s unrealistic to expect people to understand the details of an example during a short presentation. You can tell them why it’s useful and interesting, maybe a bit of how it was made, but a presentation isn’t a good alternative to the documentation. I think it’s better if the presentation is inspiring rather than informative — you can get people excited about the possibilities, so they later try it out. Or give some indication of history and goals; something that can’t be expressed in the code alone.
I like the security example, because it’s compelling and solves a real problem that many people can relate to. Or some other concrete example; vague concepts and patterns (what does keyable mean?) are just going to leave everyone wondering why they should care. You have one abstract concept you are trying to explain: generic functions. You really want everything else to be concrete, otherwise it’ll be a distraction, one more thing to explain.
I thought maybe something showing dynamic addition of new generic functions throughout the lifetime of an application would be cool.. i.e. using generic functions as a unit of composition in an app. (I made an IRC bot that allowed users to add new commands from an IRC channel, which were represented by extensions to a base generic function).
Also, a set of generic functions for tree traversal viewed side-by-side with a Visitor pattern implementation. Pretty much any visitor method that contains conditional logic operations on the arguments is a candidate for refactoring to generic functions. I’ve done a couple of these for traversing Python ASTs, and they came out a lot prettier and more extensible than the Visitor equivalents.
The ease with which one can write custom method combinations is nice too, but that may be too advanced for a short presentation..
Ian: “””what does keyable mean?”””
Sorry, I guess that wasn’t clear. I wasn’t talking about using their patterns as the examples, but rather stealing the concrete examples from the book. For example, their Keyed Attribute Retrieval pattern has a nice example of discount pricing rules by customer and product.
You’re probably right about security rules being the best concrete existing example I have, though.
Andy: “””I made an IRC bot that allowed users to add new commands from an IRC channel, which were represented by extensions to a base generic function”””
Cool; where can I download it? 🙂 Seriously, an example of how somebody else is using something is always a nice credibility boost.
If I correctly understand, I would like to see what Andy Gross asked for, dynamic addition of new generic functions throughout the lifetime of an application.
I know that when I look at PyProtocols I wish there was an example where ‘something’ is handled from start thru several steps to the finish. (There may be such as example, but I couldn’t recognise it).
And especially if ‘something’ was a real problem which I understood; a security problem, tree traversal, would do.
My work is based on geomerty primitives and intersecting geometry elements is classic generic function.
Sorry for that triple post. Blogger login system is realy braindead.
This comment has been removed by a blog administrator.
This comment has been removed by a blog administrator.
What about exmples for workflow? Or an events/notification system? Could you make some clear and simple examples with those?