On Fri, May 24, 2002 at 11:45:33PM +1000, Andrew Bennetts wrote: > I personally find closures to be a cute trick that is rarely genuinely > useful (not that I've done much programming in any language with them, but > I've never found myself wishing I had them either) -- but then, so are > generators, and Python 2.2 does have those... (I've used a generator exactly > once). > > Depends on what you're doing, I guess.
Closures are really useful when you're not in OO-land. Python is most definitely in OO-land :). If you think about it, a closure's just a more simple form of an object: it's an object with one function which can have any number of data structures associated with it. However, if you're not programming in OO-style, then closures can be useful. As Gus's example showed, they're very useful for callbacks used in GUI programs, since they imitate much of the properties of objects without having to define classes, etc etc. Perfect for smaller applications. -- #ozone/algorithm <[EMAIL PROTECTED]> - trust.in.love.to.save -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
