JavaScript
Article

All I Want for Christmas: If Hemingway Wrote JavaScript

By Adam Roberts

We asked SitePoint authors what developer toys they would want for Christmas, then managed to source them — without relying on Santa.

If Hemingway Wrote JavaScript is exactly what it sounds like: A thought experiment as to how 25 well-known literary figures would tackle various JavaScript problems.

From the titular Ernest Hemingway (whose solution is terse and effective, as you’d expect), to post-postmodern darling David Foster Wallace (whose solution is long, discursive, and references his background in mathematics), pretty much everyone famous for writing in the last few centuries takes a stab at coding their way to a solution for a given problem.

The book is written by Angus Croll, on Twitter’s UI team, who knows a bit about JavaScript.

If Hemingway Wrote JavaScript

Angus Croll / No Starch Press

Why I Wanted This Book

Given I work on the content side of a technical publication like SitePoint, something that fell in the middle of those two worlds had an instant appeal. I know a bit about literature, and I like the idea of knowing a bit about JavaScript, although I haven’t quite gotten there yet. This seemed like a way to indirectly learn a bit more about the language while indulging my literary side.

The Experience So Far

I hadn’t expected to laugh so much at a bunch of code. This is a very clever, impressive book, full of amusing examples that show the versatile (or is it chaotic?) nature of both JavaScript and the English language. I haven’t covered every author yet, but some unexpected delights came from Tupac’s solution, incorporating rhyme and flow, and J.K. Rowling’s magical code.

Unsurprisingly, Kafka’s solution leads (Metamorphizes?) to a crushing bug, leading his code to recur endlessly. As Croll says, “very Kafkaesque”. A fitting end to a worthwhile read.

Which author, lyricist, stand-up comedian or orator would you want to see code? Answer in the comments, we’ll pick the best answer and send you a copy of the book!

Comments
ralphm

I'm looking forward to reading the book. But from my experience of trying to learn JavaScript, if Hemingway had learned JS I expect he still would have killed himself … only earlier.

Which author, lyricist, stand-up comedian or orator would you want to see code?

I think maybe Thomas Hardy. It would be beautiful to read, picturesque and romantic, but at the same time utterly pessimistic and defeatist … which more corresponds to how I usually feel. (Those upbeat authors are insufferable!)

MGoddard

Be interesting to see J.R.R Tolkien slinging code across the 5 kingdoms. How would the orcs deal with such power?

ralphm

It would be orcward, indeed.

Alexis2

I would love to read Douglas Adams’ javascript style, full of nonsensical characters and situations, even though we all know there will be only one answer in the end, “The Answer to the Ultimate Question of Life, the Universe, and Everything.”

brothercake

Samuel Beckett's would probably be like this:

(function()
{
	return;

})();
katja_bak

I am loving the sound of that book, I might just gift it to myself.

I think I would love to read musings on coding from someone like Nietzsche. Such pearlers as "You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist." sound like something I'd hear from my front-end friends. I'd expect to see something like;

Or

felgall

Neither of your examples look anything like JavaScript code - which is what the book is about.

katja_bak

I realise that - but I assume the whole book wouldn't be simply written code. There would be some discussion and writing about it.

Paul_Wilkins

Examples of the type of code being used in the book can be seen at http://byfat.xxx/if-hemingway-wrote-javascript

For example, Charles Dickens:

function mrFibbowicksNumbers(enormity) {
  var assortment = [0,1,1], tally = 3, artfulRatio = 1.61803;

  while(tally++ < enormity) {
    //here is an exceedingly clever device
    assortment.push(Math.round(assortment[tally-2] * artfulRatio));
  }

  //should there be an overabundance of elements, a remedy need be applied
  return assortment.slice(0, enormity);
}

which is followed by some discussion afterwards about him and aspects about him that affect how he would write the script.

katja_bak

I am familiar with this, thanks - I understand there is written code in the book. I was simply twisting it to discuss if x author (in my case, Nietzsche) wrote a tutorial-esque book on code (like the ones SitePoint puts out), how they might discuss the topic.

HAWK

Whoa, your tone is a bit off the mark here @felgall ...
I think @katja_bak's take on this is both interesting and entertaining, which is the kind of thing we like to encourage around here. wink

Paul_Wilkins

Yes it is nice. What was asked in the original post was just for who we'd want to see in code, not for examples of code itself.

We must ensure that we're not giving the impression of putting people down. Good job @katja_bak on your efforts here.

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.