Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web.
|
2006-03-09 Making things simple for busy webmastersIt's always nice when people's software saves me from having to wonder if they're up to no good by handing out obvious signs of it. Take, for example, the spate of people whose web crawling software advertises itself by having the User-Agent string of:
Evidently no one told them not to stutter. (There are a couple of
variations in what they claim to be, but that one is the most common.
Needless to say, no real User-Agent string (MSIE's included) has an
extra ' The IP addresses that sourced these are scattered all over; a couple of them are (still) on the XBL, and a couple are in SPEWS. (And I give bonus points to the person with the User-Agent string
" Another good one is the stealth spider that sends a completely blank
(3 comments.)
web/ObviousNogoodniks written at 16:42:15; Add Comment
Closures versus classes for capturing statePossibly like a lot of other people, I have a 'thread pool' Python module for doing decoupled asynchronous queries of things. The basic interface looks like this: wp = WorkPool(HOWMANY) for w in what: wp.enqueue(wrap_up(w)) wp.waitDone() res = wp.getanswers() The important operation is To keep things simple, There's two ways of wrapping up this sort of state in Python: classes
(okay, objects) and closures. In the class-based approach, def wrap_up(w): return lambda: real_func(w) The class approach is the more obvious and natural one, because the state saving is explicit. But when I wrote two structurally identical programs, the first one using a class and the second one with closures, I found that I plain liked closures better. For me, the drawback of the class based approach is that it's too
verbose. The same
(and it gets longer if you have more than one argument.) I have a visceral reaction to verbosity; in cases like this it feels like make-work. The retort is that closures are far more magic than classes for most people and it's better to avoid magic, even if the result is more verbose. For now, my view is that programming should be pleasant, not annoying, and that the verbosity of the class-based approach to state capture annoys me. So closures it is. (Perhaps the real answer is that WorkPool should have an
(2 comments.)
python/CapturingState written at 02:50:11; Add Comment
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |