Wed, 20 Jun 2007
Unintended consequences of the decorator notation
Spoke yesterday with Bill Punch, a CS professor at MSU who is using Python for intro CS. He told me his tale of tracking down what an '@' sign meant (it's a decorator, http://docs.python.org/ref/function.html). Needless to say it took him quite a while to google about and figure out what it did, because searching for '@' and 'python', in any combination you care to name, turns up many irrelevant hits.
A neat example of unintended consequences ;).
--titus
p.s. Incidentally, '@' really should be in the index, no? It's not there: http://docs.python.org/ref/genindex.html, http://docs.python.org/lib/genindex.html.
posted at: 06:41 | path: /jun-07 | 3 comments
Comments:
Posted by Kumar McMillan at Wed Jun 20 08:31:55 2007:
This reminds me of my newbie days; imagine staring at :
def foo(args, *kw):
pass
and trying to figure out what * and ** do! Well luckily searching "python def asterisk" brings up something useful now but "python def star" does not.
Maybe we should write blog posts entitled "python at sign" and "python def star" :)
Posted by Greg at Wed Jun 20 10:05:37 2007:
My friend Matt says decorators are a way to make your code harder to read :-)
In all honesty, I never got used to the syntax, it just feels too "magical" to me. I put this @ thing and now my function gets wrapped by another function? Kinda spooky.. I'm not sure why everyone else loves them? Any ideas?
Posted by Titus Brown at Wed Jun 20 11:34:55 2007:
Greg -- there's a long discussion of the rationale behind the syntax in the PEP, http://www.python.org/dev/peps/pep-0318/...