If Hemingway Wrote JavaScript

Croll, A. (2015). If Hemingway wrote JavaScript. San Francisco: No Starch Press.

Angus Croll has come up with an interesting premise for a book–take five algorithmic challenges and give each problem to five different literary giants. The result is 25 quite different JavaScript programs, each in the author’s inimitable style.

The assignments are different functions to:

  1. return the first n Fibonacci numbers;
  2. calculate the factorial of a number;
  3. determine if a number is happy;
  4. return all the prime numbers up to the value of an argument; and
  5. accept arguments in a chainable fashion and return all of them when there’s no argument.

Each section of the book is separated by poetic interludes and there is amazing pen and ink artwork reminiscent of an earlier period.

An example of those interludes is in the style of Edgar Allen Poe:

The Variable
Once upon a midnight dreary, while I struggled with JQuery,
Sighing softly, weak and weary, troubled by my daunting chore,
While I grappled with weak mapping, suddenly a function wrapping
formed a closure, gently trapping objects that had gone before.

I grew up reading and learning about the works of Hemingway, Shakespeare, Jane Austen, James Joyce, J. D. Salinger, Virginia Woolf, Chaucer, Dickens and Sylvia Plath. I’ve subsequently read books by Sir Arthur Conan Doyle, Lewis Carroll, Douglas Adams and J. K. Rowling. I also enjoy reading others’ program code.

So, for me personally, this was a match made in heaven.

function theSeriesOfFIBONACCI(theSize) {

  //a CALKULATION in two acts
  //employ'ng the humourous logick of JAVA-SCRIPTE
  
  //Dramatis Personae
  var theResult; //an ARRAY to contain THE NUMBERS
  var theCounter; //a NUMBER, serv'nt to the FOR LOOP

  //ACT I: in which a ZERO is added for INITIATION
  ...

I purchased the Kindle version of this book. I note from No Start Press’s website that had I purchased a print copy from them, I would also have been entitled to a free eBook version too.

If you’re a student of JavaScript, I thoroughly recommend this book, particularly if like me you enjoy looking at others’ programs–or at least programs written in different literary styles.

If Hemingway Wrote JavaScript is humorous and enjoyable. I hope Angus Croll is considering turning this book into a series. I would really like to see Ian Fleming tackle the Random Quote Machine challenge.

4 Likes

I have not read any book for JavaScript. If Hemmingway read or write JavaScript then it would be the best solutions ever made. Thank You!

Brilliant concept!..

I really like this book, too! Definitely recommend.