A Python surprise: the consequences of variable scope

The comment on my AClosureConfusion entry brought up a little Pythonsurprise that I had known about in the back of my mind but neverthought about fully before: the consequences of Python's scoping rulesfor variables.

Ignoring closures for the moment, Python only has two scopes forvariables: global to the module and local to the entire function.(Closures introduce additional scopes for the variables of the 'outer'functions.)

Well, sure, you know that. But the consequence is that any variablein a function


What I use asserts for

Somewhat recently a discussion came up about the proper use of asserts over on Ned Batchelder's blog, with a number of people feeling thatthey were overused or outright misused by being applied to situationsthat really should have actual error recovery. (One nice phrase usedwas 'exploding comments'.)

I'll admit it: I use asserts in my code. I use them when I don't thinksomething can happen in an algorithm, but I'm not absolutely sure andif I turn out to


Unix folklore: using multiple sync commands

There is persistent bit of folklore in the Unix world that you shoulddo several sync commands before shutting down or rebooting a Unixmachine. Even today, you'll see a lot of people following thisfolklore, generally using ' sync; sync; sync '.

People who do this irritate me, because they are doing it wrong and ina way that makes the whole folklore ineffectual.

The sync folklore dates from the very old days when Unix was primitiveand two things were true. First, the sync()


A thought about free software licenses

It's recently occurred to me that one way to think about the GPLversus BSD/MIT licensing issue is that they are embodying twocompeting bits of psychology: people want to share their work and haveit widely used, and people don't like being taken advantage of.

(Although it may be surprising, there is quite a bit of evidence thatwe are in some sense wired to feel strongly about 'unfairness' and topunish it, even at a cost to our own interests. Psychologists havedone


Thinking about a closure confusion

Consider the following Python code, which is a very simplified versionof certain sorts of real code that people write:

ll = []for i in range(1,10):  ll.append(lambda z: i+z)print ll[0](0), ll[8](0)

A lot of people writing Python code like this for the first timeexpect to see it print '1 9', when in fact it prints '9 9'.

What I think


Weekly spam summary on December 24th, 2005

Merry Christmas and happy holidays to all, and to the spammers a lumpof coal since they do not seem to be taking time off at all.

This week we received 14,342 email messages from 206 different IPaddresses. Our SMTP server handled 74,689 sessions from 6,178different IP addresses. Received email is down from last week , which is no surprise since theuniversity knocked off for Christmas holidays on Wednesday, butsession volume is way up.


When comment spammers attack

WanderingThoughts has been getting little one-off bits of comment spamfor some time , but late last night I had myfirst actual comment spam attack run. There's a number of interestingand odd little bits about it.

The first sign of trouble was a single comment spam posted in theevening of December 20th, from a PacBell DSL line. I removed it prettyrapidly, but on December 23rd the spammer came back from various otherIPs to post 12 more spam comments between 3:


Why the (Sun) JVM is irrelevant to me

In this entry ,Ian Bicking responds in part to Tim Bray's On Beyond Java -- the JVM and comments as an aside that he's indifferent to the JVM. Iwant to expand on Bicking's aside, because I am in much the same boatas him. Here's the pragmatic reasons why the (Sun) JVM is prettymuch irrelevant to me:

  • it's a 46 megabyte download (for the JDK; the JVM alone is smaller).
  • ... with an

What I really want is error-shielding interfaces

Recently (for my version of 'recently'), the blogosphere had a littletiff about 'humane' versus 'minimalist' APIs, starting with MartinFowler's article andcontinuing onwards (there's a roundup here ).To caricature the positions, the minimalist side feels that APIsshould have only the basic building blocks, and the humane side feelsthat APIs should have all of the commonly used operations.

(Part of the fun of the whole exchange is that it got framed as a Rubyversus Java


How to get your web spider banned from here

To get your web spider banned here, do as many of the the following aspossible:

  • make a lot of requests, so that we notice you. 1,500 over two days,for example.

  • make repeated rapid requests for the same unchanging pages, incase the sheer volume didn't get our attention. Over the same twodays, fetch something that hasn't changed since June 18th eighttimes and a bunch of other similar pages seven times each.

  • to make sure we notice