If Hemingway Wrote Javascript by Angus Croll

Reviewed for Nomadic Journal.

Angus Croll’s book-length thought experiment adds a new twist to the common trope in technical writing of using literature as dummy text for exercises: This time the literary references are the exercises. In If Hemingway Wrote Javascript the literary masters tackle classic programming problems in ways that will be recognizable to well-read programmers, with style to spare. Borges, Lewis Carroll, Dickens, and David Foster Wallace devise algorithms that generate prime numbers. (At least two of these authors would not have been out of their element here). James Joyce, Jane Austen, Arthur Conan Doyle, and Jack Kerouac take on factorials. Can you guess whose code has a jazzy, improvised feel? and whose abounds with neologisms and non sequiturs? Croll plays the role of omniscient narrator, offering post-code explanations that dig into the rationale behind each writer’s approach.

Hemingway comes at a pivotal time in the history of the modern web’s lingua franca. With the advent of standards-compliant browsers and Ajax, and Javascript’s ensuing emergence as a Serious Programming Language, there has been a call for greater adherence to a set of best practices and even style rules. The call has been heeded, with syntax-checking tools like JSLint and JSHint hastening along the standardization of the notoriously flexible, forgiving language. Against these developments, If Hemingway Wrote Javascript offers a playful rebuttal, showing us that the language can, in the hands of stylists, be a vehicle for self-expression, or at the very least the expression of a style.

Because each of our secret Javascript adepts has such a distinct voice and approach, style and syntax can’t be ignored. But while he is regaling us with a thought experiment, appealing to Javascript and literary nerds alike, Croll is making a quasi-serious point. Taken as a whole, the exercises in style contained within Hemingway make a case for the will to style. Style is not allowing ourselves to be hemmed in by dogma and doctrinaire thinking. It is an affirmation that the manner in which we do something is almost as important (and surely as interesting) as the results, following the examples of the literary greats. Just think of how many words—new descriptive tools—Shakespeare coined that are now in common usage, all at the service of retelling Boccaccio.

As in literature, there are many ways to say the same thing in a language as flexible as Javascript. That notion is stretched to the extreme in Croll’s scenarios, with often comic results. In Roberto Bolaño’s Fibonacci’s sequence algorithm, he bunches all of the program’s heavy lifting into one claustrophobic line, with a word to the wise in the comments:

//Everything is getting complicated.

for(var i=2,r=[0,1].slice(0,l);i<l;r.push(r[i-1]+r[i-2]),i++)

Then, for no reason, he defines a long list of important mathematicians which are never referenced again in the program.

rationalTheorists = [“Archimedes of Syracuse”, “Pierre de Fermat (such margins, boys!)”, “Srinivasa Ramanujan”, “René Descartes”, “Leonhard Euler”, “Carl Gauss”, “Johann Bernoulli”, “Jacob Bernoulli”, “Aryabhata”, “Brahmagupta”, “Bhāskara II”, “Nilakantha Somayaji”, “Omar Khayyám”, “Muḥammad ibn Mūsā al-Khwārizmī”, “Bernhard Riemann”, “Gottfried Leibniz”, “Andrey Kolmogorov”, “Euclid of Alexandria”, “Jules Henri Poincaré”, “Srinivasa Ramanujan”, “Alexander Grothendieck (who could forget?)”, “David Hilbert”, “Alan Turing”, “John von Neumann”, “Kurt Gödel”, “Joseph-Louis Lagrange”, “Georg Cantor”, “William Rowan Hamilton”, “Carl Jacobi”, “Évariste Galois”, “Nikolai Lobachevsky”, “Joseph Fourier”, “Pierre-Simon Laplace”, “Alonzo Church”, “Nikolai Bogolyubov”]

Anyone who has tackled the author’s sprawling epics, 2666 or The Savage Detectives, will recognize this device right away as vintage obsessive, exhaustive Bolaño derailing his own well-laid plans. In the postmortem, Croll characterizes Bolaño’s approach as “messy, sprawling, and inconsistent, liable to lurch into pages of tangential minutiae or take a sudden turn that orphans erstwhile heroes and leaves tantalizing plotlines unresolved.” One could argue that the popularity of both Bolaño and Twitter is at least partly attributable to a common homologous structure: the nested story. Twitter conversations can go several layers deep and spawn any number of spin-off conversations, leaving us tabbed out and craving resolution. Incidentally, Croll, when he is not devouring the classics and soon-to-be-classics, works as an engineer at Twitter.

So why isn’t our code as rich and variegated as these examples? For reasons which will be obvious to any seasoned programmer: the quest for elegance, or, more apt to a discussion of Javascript, unobtrusiveness. Elegance in programming is exclusively concerned with clarity and brevity. In this technical sense of the word, Hemingway’s prose is not too far off the mark. When being understood is of the utmost importance, I’ll take Hemingway-inflected Javascript over Joyce any day. Happily, in literature, Hemingway’s is not the only possible voice.

As an engineer and an astute reader, I doubt Croll harbors any illusions that “code is poetry,” one of many rallying cries of the open source community. The book’s examples are more farce than anything approaching production-grade code. Code may aspire to be more like poetry in the rare confluence Croll has created for our geeky enjoyment, but for the most part code is making the world more standardized, not less. The efficiencies introduced by software developers that have transformed the economy and changed the way we communicate have been built on a bedrock of mechanical elegance and instrumentalized crowd psychology, not poetics. Logically there is no equivalence between code and poetry not because poetry cannot be code—Oulipo proved that it could be, the Flarf poets less convincingly—but for the simple reason that code is not poetry. Not yet at least. Code is instrumental language designed to be interpreted by machines and their operators in order to accomplish defined goals, while poetry, at its most expressive (and subversive) is de-instrumentalized language that disrupts, to borrow a phrase from the start-up lexicon, as it decodes and recodes the usual flows of language, which are always threatening to petrify into inert, perfunctory sayings.

One of the first programming books I laid hands on used excerpts from Kafka’s Metamorphosis as dummy text in its exercises. Before I’d read any Kafka I knew the first line of that story: “When Gregor Samsa woke up one morning from unsettling dreams, he found himself changed in his bed into a monstrous vermin.” Since then I’ve known quite a few programmers who have read Kafka. The Kafka-reading programmer is a bit of an anachronism, possibly a systems analyst debugging code in a cubicle on a Friday night when all of the others have left, an uncomfortable, though no less dutiful, cog in a large bureaucracy. In purely literary terms Croll really has understood Kafka, Kafka the absurd humorist, whose early translators saw fit to correct his tonal “mistakes.” Fittingly, Kafka’s is the only exercise in the book that does not resolve itself. It loops infinitely. Kafka the coder is aware of the bug but is himself useless to fix it; he merely notes in the comments that a “hideous bug” has been introduced. Croll saves this, his best trick for last. It almost feels poetic, this broken code, calling to mind Benjamin’s remark about Kafka: “There is nothing more memorable than the fervor with which Kafka emphasized his failure.”