Apr 012004

Immersed, by necessity, in technical matters lately, I began to wonder what my vocation, software, and my avocation, poetry, have in common. (Meanwhile my readers, if any remain, began to wonder if I was ever going to post again.) The literary lawyers go on about the intimacy between poetry and the law and compile an immense anthology devoted to attorney-poets. Who better to speak for the programmers than I? And I do have some company in these two interests: Richard Gabriel, the well-known Stanford computer scientist, is a poet, and among the poet-bloggers Mike Snider and Ron Silliman, two poets as different as you’re likely to find, both write software for a living. Less illustrious, perhaps, than Wallace Stevens and James Russell Lowell and Archibald MacLeish, but computer science is an infant profession while the lawyers have been with us forever.

What the programmer shares with the poet is parsimony, and here we leave law far behind. Programmers, like poets, often labor under near-impossible conditions for practice, and for fun; Donald Knuth, responsible for TeX, the world’s best typesetting program, says that his favorite program is “a compiler I once wrote for a primitive minicomputer that had only 4096 words of memory, 16 bits per word. It makes a person feel like a real virtuoso to achieve something under such severe restrictions.” A popular game in computer science is to try to write the shortest possible program, in a given language, whose source code is identical with its output. Is this any different from writing poems in elaborately complex forms, like sestinas or villanelles, or playing bouts-rimé? In a sense, it’s the constraints that make the poetry.

Successive versions of the same program shrink, even as they improve. In Version 1.0 the developers usually lack, like Pascal in his letters, the time to make it shorter. In 2.0 excess code is pruned, methods and interfaces are merged that at first appeared to have nothing in common, more is done with less. Successive drafts of the same poem shrink the same way, for the same reason. The Waste Land was supposed to have been cut by Ezra Pound from five times its present length. (Pound claimed that he “just cut out all the adjectives.”) Whether it wound up any good is a topic for another day; that it wound up better than it started no one can reasonably doubt.

Good programming requires taste. Certain constructs — long switch or if/else blocks, methods with a dozen arguments or more, gotos, labels, multiple return statements, just about anything that looks ugly on the page — these must make you queasy, your fingers must rebel against typing them. Some programmatic and poetic strategies look eerily alike. The classic way to avoid switch and if/else statements in code is polymorphism, which closely resembles ambiguity in poetry.

Donald Knuth maintains a complete list of errata for all his books, and pays $2.56 ($.028) for every new error you find. In most human endeavor the perfect is the enemy of the good, and many people who have never written a program or a poem might regard Knuth’s quest for perfection as insane. Randall Jarrell once defined a novel as “a long stretch of prose with something wrong with it,” which is amusing but overbroad. A poem is a stretch of verse with something wrong with it; a program is a stretch of code with something wrong with it. A novel is a stretch of prose with something hopelessly wrong with it. For poets and for programmers, perfection seems always a few revisions away. This may be an illusion, but it’s an illusion that the novelist, the civil engineer, certainly the lawyer, cannot share.

In truth, however, yesterday’s code had more in common with poetry than today’s. The great lyric code poems, the brilliantly compressed algorithms, have mostly been written, and live on in the native libraries that all modern programmers use but few read. They are anthologized in Knuth’s three-volume opus, The Art of Programming, one volume each for fundamental algorithms, semi-numerical algorithms, and sorting and searching. Where yesterday’s tiny assembly programs were lyric, today’s n-tier behemoths are epic, and epic programs, like epic poems, never fail to have something hopelessly wrong with them. Nonetheless, in programming we have entered the age of the epic, and there’s no going back. Once, in a bout of insanity, I interviewed for a programming job at a big bank, and encountered a C programmer who liked to work close to the metal. He asked me to write a program that would take a string of characters and reverse it. I asked if I could use Java and he said sure. My program was a one-liner:

string reverse ( string pStr )
return pStr.reverse();

The point being that Java has a built-in method to reverse a string, called, remarkably, reverse(). Now I knew exactly what he wanted. He wanted me to use one of the classic algorithms, which have been around since at least the 1960s and are described in Jon Bentley’s excellent book on programming in the small, Programming Pearls, among other places. He wanted a nostalgia tour. But these algorithms are great poems that have already been written. Any decent function library, like Java’s, includes them, and it makes no sense to reinvent them, priding yourself on your cleverness. I didn’t get the job.

(Update: Rick Coencas comments. mallarme comments. Ron Silliman points out in the comments that he’s not a software developer after all; I apologize for the error.)

  21 Responses to “Code Poems”

  1. for what it’s worth, while law may not have much in common with poetry, i find writing briefs to be very, very much like programming. same modular structure, same endless search for elegance, for the path that one must take to a certain destination, etc. logical argument is logical argument, whatever the context (and law has shortcuts just like programming, cites to other cases, analysis much like a subroutine, etc.).

  2. As a poet and programmer myself, I’ve often noticed the similarities. Apart from working within constraints that parallel poetic forms, scripts often seem like free verse to me. The way it looks on the page/screen, choosing exactly the right words/variable names, and improving the flow and logic are concerns for me whether I’m coding or rhapsodizing.

  3. Sometimes a program is just a program.

  4. This is very interesting. I am not a programmer, but have often thought I would like the work — elegance, in code and poems.

  5. But how then does one explain Microsoft Windows, a program that grows neither leaner nor faster with each successive release?

  6. The closest literary analogue to Windows would be something like L. Ron Hubbard’s Mission Earth series, probably.

  7. How about Leaves of Grass?

  8. Nah. Leaves of Grass started out thin.

  9. Amen to not wanting to reinvent the wheel.

  10. I don’t write software for a living. I’m a market analyst focusing on infrastructure support services.

  11. Sorry Ron. Certain comments on your blog led me to believe you did. I will publish a correction.

  12. Why aren’t I paid Knuth’s going rate to find bugs?

    Disgruntled tester.

  13. mrs,
    You can start paying a grammar teacher first.
    [sorry, couldn’t resist. Although I just spelled "hare" as "hair" and my correspondent is probably ROFL]

  14. NEW POST, NEW POST, NEW POST — NOW!! ‘Ya Lazy Bum!!

  15. Can I get a cash payment for pointing out that $0.02 ^ 8 is 0.0000000000000256 dollars^8?

  16. No dice. $0.02 = 2 cents, and 2 cents ^ 8 = 2 ^ 8 cents = 256 cents = $2.56. Take it up with Knuth.

  17. Yeah, yeah code is poetry. When are you going to write about about real peotry that isn’t really poetry — rock lyrics?

  18. There is code that is poetry and then there is poetry that is written like code.

    Check out the home page at http://www.rastasoftware.org for an example of what I’m referring to

  19. Oops my mistake, that should have been http://rastasoft.org/

  20. […] My resurrection called for new software, and a cursory survey of the alternatives led me, on a Wisdom-of-Crowds basis, to WordPress, a collection of PHP scripts. The WordPress slogan is “Code Is Poetry.” a href=”http://www.godofthemachine.com/?p=540”>I agree; but if code is poetry, WordPress code is doggerel. Here’s a sample from their Greymatter import script: […]

  21. […] “Programmers, like poets, often labor under near-impossible conditions for practice, and for fun…” Aaron Haspel writes. […]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>