slaniel | Uncategorized | Thursday, May 31st, 2007
You could implement a very basic cat(1) in Perl in 6 lines:
#!/usr/bin/perl use strict; use warnings; print while(<>); exit(0);
(The advantage Perl has is that if you run mycommand.pl file1 file2 ... fileN, it’ll basically behave as though you had done cat file1 ... fileN | mycommand.pl, and it uses the <> shorthand to read one line from standard input. This is in keeping with Perl’s habit of using magic where Python would eschew it.)
As far as I can tell, the quickest way to do the same thing in Python is like so:
#!/usr/bin/python import sys if len(sys.argv) == 1: for line in sys.stdin: print line, sys.exit(0) for file in sys.argv[1:]: f = open(file) for line in f: print line, f.close() sys.exit(0)
Can anyone think of a shorter way to do this in Python?
The special-casing for sys.stdin is a little grating. I’d like to rewrite the above like so:
#!/usr/bin/python import sys def cat( listoffiles ): for file in listoffiles: f = open(file) for line in f: print line, f.close() def main(): files = sys.argv[1:] cat( files ) sys.exit(0)
but still there’s the special case for sys.stdin. I could use isinstance(), but that’s ugly (switching on type) and frowned upon.
I could always write a function that takes filehandles or filenames and coerces them all into filehandles, which I could then pass on to cat(). But that still seems like special-casing.
Is there a good way around this?
slaniel | Uncategorized | Wednesday, May 30th, 2007
I am obsessed with this album. I found it on Doug Zongker’s blog, which I in turn found because of the Chicken Chicken PowerPoint presentation. You should go ask your friendly neighborhood library if they have it. If you’re lucky enough to live in Massachusetts, the Minuteman Library Network has it.
Comments Off
slaniel | Uncategorized | Wednesday, May 30th, 2007
Couldn’t hold my interest. On we move to Maynard Smith’s Evolution and the Theory of Games, which — at least so far — covers the same ground as Bowles’s Microeconomics. In its treatment of evolutionary game theory, the only big difference so far is that Bowles is dismissive of mixed strategies (i.e., choose amongst pure strategies at random) while Smith makes extensive use of them. In a footnote on page 34, Bowles writes:
While mixed strategies sometimes provide a handy modeling device . . . for technical reasons they have been given much more attention by game theorists than is justified by any resulting illumination of human behavior.
(I believe the technical reason here is that under certain conditions, finite games all have Nash equilibria in mixed strategies, whereas they don’t necessarily have them in pure strategies. But don’t hold me to that.)
Comments Off
slaniel | Uncategorized | Tuesday, May 29th, 2007
I had been looking forward to reading Ernst Troeltsch’s Social Teaching of the Christian Churches ever since I read former CMU College of Humanities and Social Sciences Dean Peter Stearns praise it. I gave it a hundred pages to get me enticed, but it failed. The reasons probably aren’t worth going into, but in any case it’s now back at the library for someone else to attempt.
So I switched to Cybernetics: Control and Communication in the Animal and the Machine, the famous book by Norbert Wiener. There’s something deliciously strange about the introduction. I think it might be how quickly Wiener switches from information theory to feedback mechanisms to economics and sociology, and then finally to the morality of his own work. As for that last item: Wiener did a lot of work for the U.S. military during World War II, and Cybernetics came out just shortly after the U.S. dropped the Bomb on Hiroshima, so he’s all too aware that science is not morally neutral. His honesty in the intro to Cybernetics is refreshing; he knows that using machines for process control could impoverish industrial workers even more, so he says that a scientist might be well-advised to focus his research on areas as far away from human contact as possible.
I’m pretty sure I’m in the presence of a literate, realist polymath. I can’t wait to dive in.
slaniel | Uncategorized | Tuesday, May 29th, 2007
Universal Hub mentioned it, so it seems valuable to spend a second talking about the vision of Boston in 2017. I didn’t really look over it much; I checked out the Science City bit and stopped when I got here:
Because high housing costs are hurting Greater Boston’s ability to retain its labor force, the growth into extended suburban areas is acting as a pressure-release valve. After all, the State New Economy Index wasn’t topped by Cambridge or Boston, or even Route 128 — it was a blue ribbon shared by Massachusetts as a whole. So, while some planners imagine a strand of innovation running between BioSquare in Boston and Harvard Square in Cambridge, others are thinking more broadly, envisioning a biotech super-corridor anchored on one end in Worcester and the other along Massachusetts Avenue. Timothy McGourthy is Worcester’s economic development director, and in his view, “Massachusetts doesn’t have a housing problem. It has a transportation problem.” Just imagine if a vibrant tech cluster centered on Springfield’s Bay- state Medical Center were just an hour and 20 minutes away by high-speed rail.
If you believe that Future Joy will come from a Greater Massachusetts Co-Prosperity Sphere extending well beyond dense cities, and in all likelihood creating some kind of edge-city no-man’s land between here and Worcester, you and I are not talking about the same goals.
If you then cover your tracks somewhat, appealing to us dense-city advocates by placing the words “high-speed rail” where everyone else would say “cars,” you are living in a state whose government is unfathomably more agile than the one we have here in Massachusetts.
Comments Off
slaniel | Uncategorized | Tuesday, May 29th, 2007
I’d like to second Adam Rosi-Kessel’s endorsement of a This American Life parody (and while I’m at it thank him for introducing me to it). It’s quite hilarical. I’ll also link directly to the 7.6-meg MP3, because Firefox for some reason has a hard time converting relative links to absolute ones when they’re inside of <embed> tags.
And I’ve cached it, because why not.
slaniel | Uncategorized | Monday, May 28th, 2007
It’s All Text! is very cool, but I wonder if something even cooler would be possible: embedding a full text editor inside of any textarea field. Wouldn’t it be cool if you didn’t have to leave your browser to get all the love that’s in your editor?
I know not the first thing about writing something like this, but I’ll look around.
slaniel | Uncategorized | Sunday, May 27th, 2007
I can’t decide if it’s good or unfortunate that the more I read, the more I want to read. There is no fixed number of books that I need to “get out of my system”; the number I need to get out of my system increases, the more I get out of my system.
Like I said, I can’t decide if this is a good thing.
The Social Sources of Denominationalism is a little oddly structured. The first chapter or so is a passionate assault on divided Christianity, as I mentioned before, eliding into an enumeration of the various ways in which sects form. The first half of this enumeration is about the European churches, and the latter half is about how those European churches evolved under the forces of frontier individualism in the United States. Among the predictable consequences of the frontier is that churches with strong hierarchies — like the Catholic church — would tend not to survive, and those emphasizing individualism would thrive. The picture is more complicated than this, but it’s one of many causes of sect formation that Niebuhr lays out. The book must be saluted for its patient explanation of the economic, social, linguistic, and racial sources of sect formation.
Only at the very end does Niebuhr return to the strident tone of the first chapter; the effect of the middle is kind of dulling. If you’re not already familiar with what makes Presbyterians different from Episcopalians, makes the latter different from Methodists, makes all three different from Baptists, and differentiates all the various divisions therein, the middle part will be slow going. It’s intriguing at parts, though, for the uninitiated; I didn’t know, for instance, that the Baptists (no adjective) were at all different from the Southern Baptists, but apparently the latter were a splinter sect of the former; the Northern Baptists were anti-slavery.
Niebuhr’s recommendation, in the final chapter, is that all the Christian churches rediscover their common core of Christ’s love and cast aside all that has separated them. He says that this common core has emerged at various times in various movements throughout the history of Christianity, and that it would take a church devoted to the teachings of Christ and Paul to rediscover it.
I hope I’m forgiven for finding this plea unconvincing, in the light of the 200-odd pages that have gone before it in Niebuhr’s book. He has just told us about the virtual inevitability of sect formation under numerous influences, and how churches have almost uniformly recreated the divisions in their larger societies, and only spends a few pages at the end arguing that churches can overcome these divisions if they just try hard enough. Color me skeptical.
slaniel | Uncategorized | Saturday, May 26th, 2007
I periodically wonder which modern jobs and activities would be hardest to explain to someone from the Middle Ages. Yesterday I nominated Search Engine Optimization, though it’s just a nominee rather than a clear winner.
Just now I discovered LOLMaps. It is a purely meta website, referencing LOLCats, which is itself a site whose sole purpose is to attach captions to photos of cats, while including copious Internet grammar (“O HALP! yor my only hope..”).
If anyone can suggest a less-explicable modern idea, let me know. In the meantime, we may have a winner.
P.S. (29 May 2007): The involution curls deeper and deeper into its own buttocks.
Comments Off
slaniel | Uncategorized | Saturday, May 26th, 2007
. . . I am going to bestow my ample Google cred on her new website, Deciders of Awesome. It is a fantastic website, and very funny. It’s like The Superficial, only more caustic — as if The Superficial had been filtered through Annie, oddly enough. Highly recommended.
Comments Off
slaniel | Uncategorized | Thursday, May 24th, 2007
It’s sad that the MBTA says the fastest mass-transit route from work to North Station basically involves traversing three sides of a square, and takes 37 minutes or so. The walking distance from here to there — traversing just the remaining side of the square — is 1.9 miles or so, which I could walk in about 38 minutes. I’m inclined to walk it when I hop on Amtrak tonight.
slaniel | Uncategorized | Thursday, May 24th, 2007
I don’t know exactly what’s going on with Twitter, but service has been spotty in recent weeks. If I had to guess, it’s that Twitter’s suffering from what ailed Friendster: it grew too fast, and the capacity didn’t keep up with it.
I’m surprised that websites still need to deal with this. You’d think that in an age of effectively costless bandwidth, massive CPU overcapacity, and technologies like BitTorrent and SETI@Home, that there would be some way of spreading all relevant resources over many machines at once, without even thinking about it. Instead I’m pretty sure that new popular websites need to go the old route, namely buying lots of big boxes and sitting them behind fat pipes. Seems not right.
If you’ve not used Twitter, it’s pretty cool. All it is, is a group distribution list for text messages, that also lets you send via IM (though the IM function has never worked for me, and it’s not working for anyone recently). It’s an interesting use of technology. It’s another device for quickly telling large groups of your friends what’s happening in your life — a position also occupied by web bulletin boards, IM, text messages, and who knows what else. It’s just created a nice little niche, where people sitting at their computers at work can toss off Twitter messages with a nonchalance that they couldn’t quite pull off if they had to take a phone out of their pockets and send a text.
slaniel | Uncategorized | Wednesday, May 23rd, 2007
Python seems to do everything with exceptions. It’s led to a little bit of frustration on my part, where — for instance — I’ve wanted to figure out what value os.kill() returns, and as far as I can tell the answer is: it doesn’t; it only throws exceptions. What I want to be able to do is
def killandreact( pid ): killresult = os.kill( pid, signal.SIGKILL ) if killresult.processisdead: doSomething() else: doSomethingElse()
Why bother with exceptions when you could return a very rich object? The kill_result object here could contain all kinds of information about the process we tried to kill, anything that happened along the way, an English-language message about the result (“Couldn’t kill process because you don’t have permission to do so” — something like Perl’s dollar-bang ($!, a.k.a. $ERRNO) variable, only contained inside an object rather than global), etc., etc. Why bother with exceptions?
I’m sure there’s a good reason. I’m just not well-versed in exception-handling generally. What’s the virtue of using an exception over a return value? Offhand, it seems like you’d have to be very careful with exceptions: make sure that whoever calls the thrower knows what to do with what it catches, or else the exception might be thrown several layers up the stack to someone who doesn’t know what to do with it except crash. I guess something similar could happen if you use return values: the caller doesn’t handle every possible outcome from the callee, leading to consequences that may in fact be worse than unhandled-exception errors or generic “exit the application” exception handlers.
So what’s the magic that I’m missing?
slaniel | Uncategorized | Wednesday, May 23rd, 2007
Shouldn’t it really be called “menostop”?
I’m just asking here.
Comments Off
slaniel | Uncategorized | Wednesday, May 23rd, 2007
During an email riff with Adam Rosi-Kessel yesterday, I noticed that OnionArticlesThatArent.com was available, so I took it and started a little blog there for “legitimate” news articles that really ought to be in The Onion. I hope you enjoy it. Design suggestions (I wanted to get something started; I’ve not really honed the details at all), article submissions, etc. are all welcome.
Comments Off
Despite the possibly cold- and academic-sounding title, The Social Sources of Denominationalism is actually a passionate, engaging read. Perhaps 1/4 of the way through it, the premise thus far is that the rise of Christian sects shows that the Christian churches have failed in their ethical duty. They should all be preaching the single unified truth of Christ’s love, says Niebuhr, whereas instead they each reflect the economic and social traits of the people in their sects.
Throughout history, says Niebuhr (brother of the more-famous Reinhold Niebuhr), sects have arisen when their parent church has grown remote from a vital Christianity; sects are a continual attempt to renew the religion. Also, says Niebuhr, the revolution and the new sect have always come from below: the existing church tends to gain respectability over time, and gain middle-class adherents, thereby drawing further and further away from an emotionally appealing experience of Christ and more towards a cold, academic understanding of God. The poor, says Niebuhr, have always sought a more direct — emotional, arms flailing, speaking-in-tongues — connection with god, which “respectable” churches are loath to provide. And those respectable churches are much better at telling the poor to mind their own business and accept their station, than they are at elevating that station.
So ultimately, the “ethical failure of the divided church” (title of the first chapter) is the church’s failure toward its most needy members. The presence of sects is not the church’s failure — rather, its failure is to have made those sects necessary in the first place.
Thanks to Jason Smith for recommending this book to me, as a precursor to Ernst Troeltsch’s Social Teaching of the Christian Churches.
slaniel | Uncategorized | Wednesday, May 23rd, 2007

It’s from a random website, via TikiRobot.
I’ve written checks for, say, 25 and 9/20 dollars, with “25.45” in the little box. I thought I was clever. Most of the time the bank accepted the check, but at least once it was returned to me. I imagine the bitter sneer with which the bank clerk stuck it in the mail.
In that case, though, I intended to pay $25.45. The check above, on the other hand, is valued at $0.002, because eiπ equals -1, and the sum from n=1 to n=infinity of (1/2)n equals 1. I wonder whether he really intended to write a check for that amount. More amusing, from my perspective, would be to write a check for something like -25.45 times eiπ. But that’s me.
slaniel | Uncategorized | Tuesday, May 22nd, 2007
It’s quite common in C to pass in a buffer, which the function will fill up. If the function has any problem filling it, it’ll return some error. That idiom doesn’t seem to exist in Perl and Python: if you want to return a complicated data structure, you return it; you don’t fill up one of the arguments. Does anyone know why C works this way and other languages don’t?