DEV Community

Cover image for Book Review - If Hemingway Wrote Javascript
Cameren Dolecheck
Cameren Dolecheck

Posted on • Originally published at imago.dev on

Book Review - If Hemingway Wrote Javascript

What would computer code look like if it was created by history’s greatest writers? How would some of the most creative linguistic minds take to writing Javascript? Angus Troll attempts to answer those questions in “If Hemingway Wrote Javascript”.

This is a cross-post from the blog I run, Imago Dev.

This book takes an entirely different approach to coding and style. Croll solves a handful of common programming challenges, such as finding Fibonacci or prime numbers, in a matter fitting a wide variety of famous writer’s styles. Some solutions, like the first example by Hemingway, are down right elementary; however, some like Italo Calvino turn functional programming on its head.

Often times, comments in the code work to tell a story more so than simply describe the lines of code. Some authors throw out form all together, combining code and comment into one string of thought. For instance, the beat generation writer Jack Kerouac’s solution to factorial, writes the whole program as essentially a single line.

/*...the only numbers for me are the mad ones, take forty-three like a steam engine with a talky caboose at the end*/ (n = 43), /*and that lanky fellow in a cocked fedora*/ (r = 1); /*then back to our number, our mad number, mad to become one*/ while (n > 1) /*mad to descend*/ n--, /*mad to multiply*/ (r = r * n); /*and at the end, you see the blue center-light pop, and everybody goes 1.4050061177528801e+51…*/
r;
Enter fullscreen mode Exit fullscreen mode

It’s so wonky that I had to turn off my Prettier VS Code extension just to save the snippet properly. You’ll also notice that he totally disregards any factorial except for that of the number 43.

Croll does an excellent job of providing a brief bio on each writer in order to set up the reasoning behind a given solution. Even if you hardly understand Javascript, you’ll walk away with a greater understanding of 25 brilliant writers. If you’re like me, this book will probably stuff up the urge to dive into some of the authors’ actual literary work.

When most folks who create code are the technical engineering types, having an artist play with the “language” part of “programming language” truly provides a fresh take on coding style. That is not to say you should emulate the topsy-turvy nature of these authors when starting the next project, but it certainly will push you to think outside the box.

Overall, this book is an excellently playful read that is worth your time.

Have you reader this book? What were your thoughts?

Top comments (0)