The following article was written by my good friend and colleague, [Angus Croll](//twitter.com/angustweets). Angus works on the web core team at twitter, talks at conferences around the world, and runs an amazing [blog](//javascriptweblog.wordpress.com) on javascript. Beyond this, he’s also a huge book nerd, so I thought it would be fun to get him to write about code from that perspective. Check it out! And let us know what you think on [twitter](//twitter.com/angustweets)!

The New Book “If Hemingway wrote JavaScript” is out in September 2014.
Pre-order your copy here!

I loved literature long before I ever wrote a line of code. Now I write JavaScript, lots of it, and I’m writing a book about it.

What is it about JavaScript that attracts so many literature devotees? I have a few half-baked theories relating to the expressive potential of a limited syntax, but that’s for another time. What about the great writers? What would they have made of JavaScript? Even as a long-time Hemingway nut, I’d be the first to admit that Papa would probably have loathed programming (and programmers). Yet I’m betting that amongst all that general contempt there would have lurked a soft spot for JavaScript, because it’s his kind of language, am I right? A spare and deceptively plain surface, masking substance and drama beneath.

Recently I had a dream in which I asked Hemingway and four other literary luminaries to write some JavaScript for me; specifically a function that returned a fibonacci series of a given length. Interestingly each author chose to solve the problem in a different way. They did pretty well actually - as far as I can tell every solution works as advertised (yes, even Andre Breton’s). Here’s what I got:

No surprises here. Code reduced to its essentials with no word or variable wasted. It’s not fancy; maybe its even a little pedantic - but that’s the beauty of Hemingway’s writing. No need for elaborate logic or clever variable names. It’s plain and its clear and it does what it has to - and nothing more.

Hemingway didn’t suffer fools gladly so if you ask for a series with less than two numbers he’ll just ignore you. “I’m tired and this question is idiotic”.

The Bard gets a little wordy here but we wouldn’t have it any other way. Notice how the comments (other than titular captions and stage directions) are written in iambic pentameter - a meter of ten paired syllables with the stress falling on the second syllable of each pair (or foot). In his plays Shakespeare often adds dramatic emphasis by deviating from strict iambic pentameter — he might add an extra syllable or use an alternate stress. It looks as though he’s using the same trick in this coding exercise. Way to go Will.

As a founding member of the surrealist movement, Breton believed dreams were more interesting than reality and should form the basis of our creative endeavors. Nouns are chosen accordingly. Although it’s easy to knock Breton, his work has aged well and is invariably heartfelt and beautiful - an unconscious upwelling of imagery folded into his own conscious expression. Here’s a translation of the gorgeous poem Facteur Cheval.

Breton has most likely named his fibonacci exercise after an old flame, while he imagines the resulting collection as a fleet of ancient vessels. The solution is underscored by characteristically elegant logic - he’s using a comma operator to simultaneously shift elements between galleons, brigantines and bassoons. Hats off Andre!

If you don’t read at least one Bolano book before you die then you’ve wasted your life. Bolano’s writing is remarkable; at once effortlessly sophisticated and charmingly naive - his narrative style is characterized by a disarmingly winsome honesty. No aspect of human frailty is off limits, but the warmth and humour with which every foible is conveyed is both engaging and uplifting.

True to form, Roberto’s exam paper is peppered with admissions of insecurity, embarrassment and ignorance. The solution, though rather brilliant, is presented as something of an afterthought. Always the obsessive, always tangential, he’s much happier offering us a mildly interesting but ultimately useless list of mathematical genii.

There are other Bolano traits here - the juxtaposition of long and short paragraphs, the absence of semicolons (mirroring the absence of quotation marks in his novels), and the use of implicit globals - suggesting that each variable is destined to make further appearances in subsequent chapters.

I’m not a fan of Dickens. Mostly I agree with Henry James’ damning assessment:

“If we might hazard a definition of his literary character, we should, accordingly, call him the greatest of superficial novelists. We are aware that this definition confines him to an inferior rank in the department of letters which he adorns; but we accept this consequence of our proposition. It were, in our opinion, an offense against humanity to place Mr. Dickens among the greatest novelists. For, to repeat what we have already intimated, he has created nothing but figure. He has added nothing to our understanding of human character.”

Henry James on Charles Dickens, in a review of Our Mutual Friend, in The Nation, December 21, 1865:

Boz’s superficiality is borne out by his fibonacci solution. Yes, there are some mildly amusing names, but a complete lack of substance and understanding at its heart. He has failed to appreciate the underlying philosophy of the fibonacci series and has instead resorted to bludgeoning his way through the problem with multiplication. Sigh.

Whether it’s Crockford’s protective albumen or the dry and narrow minded confines of computer science classes, doctrine and dogma are the enemies of good JavaScript. Some developers like rulebooks and boilerplate - which is why we have Java. The joy of JavaScript is rooted in its lack of rigidity and the infinite possibilities that this allows for. Natural languages hold the same promise. The best authors and the best JavaScript developers are those who obsess about language, who explore and experiment with language every day and in doing so develop their own style, their own idioms, and their own expression.