“Sophisticated” JavaScript
December 17, 2014
If there is such a thing as “sophisticated” literature, then there is now also “sophisticated” code. “If Hemingway Wrote JavaScript” contains many funny and educational examples.
Writers can be recognized by their style; we all remember that from school. One describes every detail of a scene and is wordy, while another just ‘scurries’ through the action. We also differentiate here between genres, whether someone writes realistically, surreally, or fantasy.
In contrast to natural languages, where every individual has their own “idiolect,” formal languages are assumed to have a standardized usage. Has anyone ever explored the question of whether there are different styles or cultures in programming? Meaning just within a language itself, not between different languages or even paradigms?
The author considered how writers would program in JavaScript if they transferred their literary idiosyncrasies to programming.
To this end, there are 25 programs by 25 well-known writers that calculate basic functions, such as Fibonacci numbers, the factorial function, or prime numbers. And here I was very surprised by the author; he really put a lot of thought into this and “invented” 25 different “programming styles.” Actually, there is something to discover in every program.
However, I can only recommend this book to programmers who know JavaScript well enough to understand the programs. Because some of the programs are quite clever, such as the loops hidden with eval and Array.join in Lewis Carroll’s program. One should also have enough basic interest in literature and perhaps already know a few of the writers. I must also admit that I didn’t know a few of them. But the writers are always briefly introduced over 2-3 pages, and then you can understand the punchlines in the code. The book encourages you to think about programming styles. Some of the programs are really easy to understand, while others are difficult, e.g., the one by Douglas Adams.
There are a few limitations, though: the author seems to be a humanities scholar himself and is very uncritical of his own guild. Also, all that social “blah-blah” from educators, sociologists, and “do-gooders” is present in the descriptions of the authors. He even writes in the introduction: “Students of the humanities are more likely to have an inductive, open-ended approach to reasoning.” That is absolute nonsense. I myself studied “Communication Research and Phonetics” as a minor alongside Computer Science as my major at a humanities institute, so I know both worlds. This would have long since gotten around in practice at companies, and job advertisements would look accordingly.
Conclusion: I can highly recommend the book. However, it’s a bit like a detective novel: once you know the solution, it’s no longer as exciting.
P.S. And I also found a small error:
On p. 96 in line 7, the call to doFissionOn() is not bold, but grayed out. When skimming the code for the first time, you think it’s a comment.
- Angus Croll
- If Hemingway Wrote JavaScript
- No Starch Press
- 2014
See also the review on Amazon.