If Hemingway Wrote JavaScript

Author: Angus Croll
Publisher: No Starch Press
Pages: 192
ISBN: 9781593275853
Print: 1593275854
Kindle: B00R8H2EP2

Audience: JavaScript developers, ideally with an interest in Eng. Lit.
Rating: 4.5
Reviewer: Lucy Black

Short JavaScript programs imagined as if created by famous literary personages from Chaucer to Douglas Adams. How does that work?

Angus Croll, who confesses that he is obsessed with both JavaScript and literature, came up with an intriguing idea, What if William Shakespeare were asked to generate the Fibonacci series or Jane Austen had to write a factorial program?

His book opens with the account of a dream in which he assigned homework to Ernest Hemingway and 24 other "literary luminaries". Prior to writing the book trying this formula with Ernest Hemingway led to a well received blog post.

Part of the appeal of looking at how writers with different styles would produce JavaScript program is that it illuminates an important aspects of JavaScript -  its capacity to accommodate variety.

As Croll puts it in the Introduction:

JavaScrpt has plenty in common with natural language. It is at its most expressive when combining simple idioms in original ways; its syntax, which is limited yet flexible, promotes innovation without compromising readability.

So to produce a book length elaboration of this premise Croll has selected a variety of distinctive and (mostly) well known literary voices to see what they would do if asked to write a JavaScript program and the result is an unusual mix of prose, poetry, code and criticism - both of writing and coding style. 

 

Banner

 

The book adopts a formulaic approach. There are five Assignment sections - Fibonacci, Factorial, Happy Numbers, Prime Numbers and Say It - and in each five famous authors submit their answers to a programming problem that is briefly described on the before we meet the "students" who are asked to tackle it. 

Although the authors are mainly well known Croll provides a succinct introduction both to the men and women concerned and to their writing styles, often with quoted passages. To introduce each character Miran Lipovaca has provided a sketch portrait of each with an apposite quotation - altered where necessary to refer to JavaScript.

By the time you reach the code you know enough about the writer to recognize some of their literary traits in the code they produce - even if this is mainly in the choice of variable names and the comments. To help your appreciation of their program Croll adds his critique of the code, which expands on both its use of literary devices and the JavaScript techniques used and here you may well deepen you knowledge of JavaScript as well as appreciating the parallels between author's writing and coding style. So for example Hemingway's Fibonacci solution is characteristically sparse and "reduced to its essentials, with no word or variable wasted". Shakespeare tackles the same problem with a two-act play in which the variables are the Dramatis Personae. 

Jane Austen's solution to wring a function that returns a factorial manages to work in her most quoted line

//It is a truth universally acknowledged ...

while another refers to a familiar JavaScript authority:

//Mr Crockford teaches that we should be
              wary of inherited property ...

James Joyce also tackles this problem and his variable names include what Croll describes as "amusingly intuitive portmanteaus" which are characteristic of his writing. 

 

hemigwayjs

 

The assignment to write a function that determines if the supplied argument supplied is a happy number is handed out to Geoffrey Chaucer and some unlikely fellow travellers, J.D Salinger, Tupak Shakur, Virginia Woolf and Vladimir Nabokov, demonstrating an eclectic taste in literature.

Douglas Adams' comment at the start of his program to return prime numbers is amusing - and predictable once you've seen it:

//Here I am, brain the size of a planet,
     and they ask me to write JavaScript...

The final section is a non-mathematical exercise - to write a chainable function. This provides an opportunity to introduce the work of Sylvia Plath, Italo Calvino. J.K. Rowling and Arundhati Roy. It also includes a program that fails. In the solution proposed by Franz Kafka the function invokes itself again and again and begins recursing endlessly with no hope of redemption. Which as, Croll points out, is very Kafkaesque. 

Four "Poetic Interludes" are interspersed between the five sections and their titles indicate that these reflect on some aspect of JavaScript. After reading, The Variable inspired by Edgar Allen Poe's The Raven and Macbeth's Lost Callback, you may be tempted to try your own hand at parody. 

I had fun dipping into this attractively produced book and part of the reason was the author's obvious enjoyment in writing it. Along the way I learned about some authors I was unfamiliar with and also some unusual, although usually not useful, JavaScript idioms.

 

Banner
 


Data Structures & Algorithms in Python

Author: Dr. John Canning, Alan Broder and Robert Lafore
Publisher: Addison-Wesley
Date: October 2022
Pages: 928
ISBN:978-0134855684
Print: 013485568X
Kindle: B0B1WJF1K9
Audience: Python developers
Rating: 4
Reviewer: Mike James
Data structures in Python - a good idea!



Modern Software Engineering (Addison-Wesley)

Author: David Farley
Pages: 256
ISBN: 978-0137314911
Print:0137314914
Kindle: B09GG6XKS4
Audience: Software Engineers
Rating: 3.5
Reviewer: Kay Ewbank

This book is subtitled 'doing what works to build better software faster' - does it teach you how to achieve that?


More Reviews

Last Updated ( Monday, 12 January 2015 )