The Programmer as Author in ‘If Hemingway Wrote JavaScript’

This inventive and engaging book imagines what JavaScript might look like in the hands of 25 writers, including William Shakespeare, Jane Austen, Tupac Shakur, and J.K. Rowling.

Imagine you have Ernest Hemingway in a room, and you can ask him anything you wish. I’d probably want to know if Heaven had turned out to be the big bull ring he’d hoped for. But when Twitter engineer Angus Croll encountered the author in a dream one night, he took a different approach. Croll challenged Hemingway to turn his talents to JavaScript and write a function that would return the first number of the Fibonacci sequence. To Croll’s surprise, Papa Hemingway did it — and it worked.

Well, what if Hemingway wrote JavaScript? What would that look like? A master of the economy of words, he might develop programming language that would meet the industry standard of function and efficiency. His imagined answer to the Fibonacci problem Croll provides is simple and direct but undeniably effective. “Hemingway’s JavaScript is plain and clear,” Croll explains, “and it does only what is necessary — and then it gets out of the way to allow the full glory of the Fibonacci sequence to shine through.” Croll doesn’t limit himself to Hemingway, however. His inventive and engaging book imagines what JavaScript might look like in the hands of 25 writers, including William Shakespeare, Jane Austen, Tupac Shakur, and J.K. Rowling.

Each author is brought back to life by Croll’s text and tasked with an assignment. Kerouac jazzes up factorials, and Salinger lets Holden Caulfield muse on unhappy numbers (“Only five numbers are really happy, that kills me”). The result of these thought experiments is clever, quirky, and absolutely executable code. If Hemingway Wrote JavaScript deftly explores the creative possibilities of programming through a series of such inspired imaginary scenarios.

Croll presents five different JavaScript tasks and assigns five authors to each. All of the authors are introduced by an encyclopedic sketch of their major works and Croll’s thoughts on them. After this, the program the author is tasked with coding is presented, upon which Croll proceeds to critique the code like one might a work of literature. He refers to Austen, for instance, as “nothing short of a well-mannered revolutionary,” describing how her fiction both emulated and ridiculed the dominant 18th-century genre of the sentimental novel. In this manner, his Austen critiques the conventions of JavaScript within her very response to Croll’s factorial assignment:

1 var factorial = (function() {

2 //She declared the ledger to be very plain. But with the happiest prospects!

3 var ledger = {};


5 return function reckoning(quantity) {

6 if (isNaN(quantity)) {

7 console.log(“I have not the pleasure of understanding you.”);

8 return;

9 }

10 //It is a truth universally acknowledged that two values an only be judged

11 //truly agreeable by means of the treble equal symbol…

12 if (quantity === 0) {

13 return 1;

14 }

And on it goes. Croll the JavaScript critic proceeds then to offer a close reading of Austen’s work, determining that while it initially appears “submissive, yielding to every overbearing commandment and pious proclamation set forth by the more pedantic leaders in our community,” it actually serves as a parody of the “social norms” of JavaScript. He provides just enough context and analysis to let the reader in on the joke, using Austen as a model of how to produce code that has fun with its own functionality.

In presenting five different takes on the same JavaScript challenge, Croll not only displays his understanding of and appreciation for the authors whose guises he adopts but also for the incredible diversity of programming language. He approaches this task with a certain joyful curiosity that proves contagious throughout the text. If Hemingway Wrote JavaScript talks back to Douglas Crockford’s JavaScript: The Good Parts, which sought to divide the programming language into its “good” and “bad” parts, emphasizing efficiency first and foremost.

JavaScript does not have to merely function; it must function, but the means to arriving at that point allot for individual technique, as Croll’s author portraits show. Programming possesses personality and style. While we have yet to see an anthology analyzing the quirks and creativity of individual programmers, this volume is perhaps a step in that direction, with Croll revealing the humanity in digital language in this conflation of famous literary figures with familiar programming idioms.

Compared to other programming, Croll considers JavaScript more creative than prescriptive. “The best authors and the best Javascript developers,” he writes, “are those who obsess about language, who explore and play with it every day and in doing so develop their own idioms and their own voice.” Every literary author Croll includes has their own recognizable style, allowing him to extrapolate that voice, translating its essence and idioms into another genre of writing. Just as we analyze the style of particular literary authors’ work, we should also consider the unique touch each programmer brings to their tasks. If you study open source code and repeatedly encounter the same person’s work, you might get a sense of their personality from how they code. Likewise, Croll demonstrates his familiarity with and affection for the authors he features by imagining what their programming would look like.

If you’re a Jorge Luis Borges aficionado, there’s a decided pleasure in judging if Croll’s interpretation of Borges-as-programmer reads as authentic. If you’re unfamiliar with the work of Arundhati Roy, on the other hand, and you find yourself drawn to her non-linear approach to Croll’s chainable function assignment, you might be inclined to pick up The God of Small Things after reading this book.

If you know next to nothing about JavaScript but love literature, this book might not be for you. To fully appreciate Croll’s portraits of famous authors as programmers, some familiarity with basic JavaScript seems, if not necessary, certainly more illuminating. If you know the most basic way to write a function that returns the first 15 numbers of the Fibonacci sequence, seeing the unique approaches that Hemingway, Shakespeare, André Breton, Robert Bolaño, and even Dan Brown take offers greater insight into the personality and styles of the authors as well as the diverse programming possibilities.

Croll may not have set out to write a “how to do JavaScript like Hemingway” textbook, but he does express a desire to create a bridge between the humanities and the technology industry. He notes that students of the humanities could be highly valuable in software development because they’re “more likely to have an inductive, open-ended approach to reasoning; they’re more likely to probe beyond the standard methodologies; and they’re more likely to question accepted practices.” I would be quite interested to see an additional volume from Croll more in this vein, one that seeks to engage the beginning programmer and, through drawing connections between literary language and programming language, teach JavaScript.

Croll effortlessly explains Shakespeare’s use of iambic pentameter, elucidating the structure and analyzing how the Bard both skillfully commands and breaks away from the poetic meter. In highlighting how Shakespeare is able to add dramatic emphasis by at key moments deviating from that poetic meter, Croll provides a useful connection between poetry and programming. Both languages have their formulas, and both can be experimented with once you’ve learned the rules.

While If Hemingway Wrote JavaScript will likely appeal most to those acquainted with coding and Kerouac, programmers who wish to approach JavaScript more creatively should find inspiration here, and even the non-programmer can likely appreciate Croll’s enthusiasm and literary humor. Miran Lipovača’s illustrations lend the book even more personality, providing portraits of the authors that capture their quirks just as much as Croll’s coding does. If Hemingway Wrote JavaScript encourages its readers to play with language and, like the authors whose guises Croll adopts throughout, find their own voices.

Splash image: Illustration of William Shakespeare by Miran Lipovača, in If Hemingway Wrote JavaScript.

RATING 7 / 10