What if William Shakespeare were asked to generate the Fibonacci series or Jane Austen had to write a factorial program? In If Hemingway Wrote JavaScript , author Angus Croll imagines short JavaScript programs as written by famous wordsmiths. The result is a peculiar and charming combination of prose, poetry, and programming.
The best authors are those who obsess about language—and the same goes for JavaScript developers. To master either craft, you must experiment with language to develop your own style, your own idioms, and your own expressions. To that end, If Hemingway Wrote JavaScript playfully bridges the worlds of programming and literature for the literary geek in all of us.
Bravo to the author of this book for successfully acquiring my money.
I didn't know what to expect with this book, but I suppose it is pretty much summed up by its title. You won't learn programming from this book and you won't get any deep insights about the featured authors.
Instead of reading this book, I would recommend looking at the list of authors who are featured in this book and getting one of their books. Hardcover would be preferable, and something substantial like Joyce's Ulysses would be most effective.
Then, after reading their book, if you are still curious how that author would have written Javascript, proceed to hit yourself in the head with their book until that useless idea leaves your brain.
And for the record, Hemingway would have written in Python.
This book is an exciting exercise. It is very amusing to see the authors code, and amusing still to know that Angus Croll is quite well versed in both coding as well as literature to pull off an idea like this. The analysis of style he provides per writer is bang on. When asked to produce a Fibonacci series for a given "n", Hemingway produces the most essential, no-nonsense code (not an extra line or variable anywhere), while Andre Braton, the surrealist, defines an array of indefinite length and puts a cap on it when he reaches a solution he desires (not very elegant a programmer would argue, but hey, its his style!)
The funniest moment in the book comes when Roberto Bolano is asked to do what Hemingway has done, and he does produce a code that works, but midway through the code he creates an unused array to store the names of some mathematicians, just like that!
Why? Well, its a homage to the mathematicians who came before him, and yes, it is perfectly alright to have that meaningless-looking info right in the middle of your algorithm. Bolano is one writer who has to define where he stands, the code can wait to produce results.
While all the writers use simple iteration to find numbers in the Fibonacci series, Dan Brown finds a secret number which when multiplied with each number produces the next number in the series. Here is how he defines it:
TheBotticelliVector = 1.61803;
This is Croll's analysis of Dan Brown's strange usage: "But wait, what’s this? It seems Brown has discovered a dark and mysterious multiplier (The Botticelli Vector, no less), which he uses to derive the next number from the one before. This arithmetic alchemy is all well and good, but we’re left wondering whether he knew he could just add the previous two numbers to make the next one. Anyway, it seems to work, so that’s probably all that matters." (A subtle jibe at Brown's secret way of fashioning his plots)
When asked to produce a general program to return the factorial of any given number n (for example, factorial of 4 would be: 4! = 4 x 3 x 2 x 1), Jack kerouac fashions his solution such that no matter what number you enter, his program will return the factorial of 43 every single time! Croll again: "because planning was so alien to his process that even functions are verboten. If you want the factorial of another number, you’ll need to pull a stimulants-induced all-nighter and rewrite it."
Seeing the way each code piece written by 25 different writers is commented on, you will notice that the intention is to hint at their literary style as well. Playfully, the book shows that the vast possibilities of both writing and coding are very reflective of the writer.
Franz Kafka, who attempts to write a code too, remains the only writer in this little book whose code never works. He attempts a very simple program but it enters a recursive loop till infinity from which an escape is impossible. The array of words that appear on screen becomes a long, terrible, useless string.
Croll's Analysis: "It’s as though it were subject to some kind of metamorphosis . . . Very Kafkaesque."
A unique genre, all it's own: literary programming books.
Here we have a survey of 25 authors, along with a JavaScript programming problem written using code in the style of that author. Croll provides a short biography of each author, a code snippet, and then some explanation of why the snippet was written the way it was.
Lots of fun and JavaScript in-jokes, but also a thoughtful exploration of the flexibility of JavaScript and some of it's more esoteric elements. Also, might even teach you a few things.
Reading this book, I am reminded first of my friend Mike. Of an evening in Baltimore at a mutual friend's home. Of vodka consumed and books given conversational chase and perhaps not a small amount of hero-worship on my part as he accelerated into his chosen field and I languished behind a copy machine at the worst-performing Kinko's in the country. [^1] House of Leaves may have been involved.
And I am reminded of my friends David and Jeffrey. Of our many lunches together and how they would veer wildly from one niche subject to another. Obsessive discussion of the high-precision clock in the Web Audio API lapses into puns cobbled together from pop songs which climb slowly into something about the Stoics.
And I am reminded, as I so often am, of that quote from Eric Miraglia in the foreword to Nicholas Zakas' Professional JavaScript for Web Developers. The one that describes front-end development as being stocked with "many liberal arts majors drafted into web-developer service during the dotcom boom". [^2] And it's with this intriguing lens that I focus as I step back from Angus Croll's If Hemingway Wrote JavaScript.
In some ways, this is the anti-Good Parts. A book that relishes in all of JavaScript's quirky crevices. All those confusing features and weird idioms and other "bad parts" that are so maligned and yet one assumes must exist for a reason. Croll puts these on display, dressing them up as though written by some of the world's literary luminaries. [^3] He puts them out there as a way of showing off JavaScript's expressiveness [^4] -- of the many ways to approach a given problem, and the many ways to solve it. (Or make a mess of it.)
And in this, it is delightfully illustrative. [^5] It shows those many approaches. It shows off those many language features. It shows off what one might accomplish with them. And in this, the astute reader [^6] will get some cheer from the light-handed (if overt [^7]) mockery Croll has made of The Good Parts -- but that same reader will also recognize the places where one's personal style and whimsy might become impenetrable to others. (But we'll acknowledge that those are all decisions we must make for ourselves, and at runtime.)
To Angus Croll: thank you for asking me to read this, and thank you for sharing it with the world. It's a real treat, and a book whose time has come.
[^1]: The actual performance ranking of that particular store is apocryphal.
[^2]: And looking again at that quote, it maybe doesn't say exactly what I remember it. But the gist is basically the same. And I know an awful lot of front-end developers that are formerly (and/or aspiring) musicians or physicists or novelists or farmers or what have you.
[^3]: And the Fibonacci assignment is so well-executed it's almost absurd. (And did you enjoy that progression? And did you get the joke re: from Hemingway to Brown?)
[^4]: And in so doing, takes a little dig on Java and its verbosity and ceremony and its own idioms and maybe just maybe he's being just a little hard on Java in the introduction there, but it's still worth laughing aloud.
as I was reading this, I thought to myself that this book is probably the only programming book out there right now that I can read in less than two weeks (and I did end up finishing it in less than two weeks). this fact reminds me that I'm still way more interested in writing and expressing than grammar (of both programming and non-programming languages), although I often wish it was the other way around. I usually try to read a programming-related book and a non-programming related-book (usually fiction, sometimes poetry or 'creative' non-fiction) at the same time, and I get through the non-programing-related book about 10x faster than the programming one, but I got through the non-programming-related book only 2x as fast as this this time around!
book reminded me about writers I've read and liked and but mostly don't think about in my day-to-day. a lot of the javascript was too advanced and/or esoteric for me and flew over my head, but I enjoyed the concepts involved and the way that Croll unpacked what he did, why he did it afterwards, and some familiarity with the writers helped to un-dry (moisten?) some javascript that is a little dry to me. this book also totally solidified the idea that I have that the javascript language is probably the most attractive and interesting language out of the programming languages I know about. haha.
I loved this book at first--it seemed written especially for me, and I laughed out loud a number of times. Croll is an excellent writer, and he shows a deep love and appreciation for both literature and javascript. Many of the code samples are ingenious, and I usually learned a thing or two from each example. But too many code samples don't really work. They bear only a superficial relationship to how I'd imagine a writer might code, such as by using variable names from character names in an author's novels (e.g., Dickens), or via strange comments, or by simply bizarre coding practices.
It's an important exercise to think about how different coding styles convey different thoughts or ways of thinking. Much of my coding style is shaped by writing in an enterprise environment, and I often need to inculcate this style in recent graduates. There is often little room for individuality in this style, since it aims for readability and refactorability. What other ways could we code? What if we aimed to write beautiful, or fascinating, or playful code instead? Is there more room for other coding styles in enterprise?
Pick your favorite author, pick your favorite JavaScript interview question, then throw the 2 together. The result is delightful. It is known that computer programming is a science, but it's also an art, and rarely have the two facts been conjoined so lovingly.
Only 3 of the authors profiled were alive @ the time the book was published. That may be because only the dead have seen the end of JavaScript. If you enjoy programming and you enjoy reading, them you will love this book. (If you don't enjoy reading, what are you doing on this site??)
To say that I love this book is an understatement. A collection of the best authors of our time writing JavaScript solutions to basic CS problems, this book does not fail to delight. Special mention to -> Shakespeare: declares variables as dramatis personae and ends loops with exeunt -> Sir Arthur Conan Doyle: Ends recursions with "whatever remains, no matter how improbable must be the truth" -> Jane Austen: Equality comparisons with "It is a truth universally acknowledged that two values can only be judged truly agreeable by means of a the === symbol" -> Kafka: Whose program didn't run because of a giant bug
While the author has done their part of thoroughly understanding how those authors used to write, I still can't figure out what this book had offered me.
Books that combine classic-literature humor and programming-language humor are obviously meant for a niche audience, but as a longtime literature obsessive who recently learned how to code, I am presumably the reader Angus Croll had in mind for If Hemingway Wrote JavaScript. Still, I’m not yet at the point where “clean,” standard JavaScript (the kind Ernest Hemingway would write) is fully intuitive to me, so I kind of wish I’d waited to read it.
The book consists of 25 brief JavaScript programs written in the style of 25 famous authors, plus commentary on how the author’s prose style is reflected in their code style. Croll’s enthusiasm shines through; these are loving parodies, animated by a sincere respect for the quirks of each author and of JavaScript itself. Still, because Croll is a fan of willfully complex, postmodern authors (Roberto Bolaño, Vladimir Nabokov, Jorge Luis Borges, Italo Calvino, David Foster Wallace), this means the book contains a lot of willfully complex, postmodern JavaScript. I did find some of the simpler programs amusing, like Charles Dickens finding a way to calculate prime numbers in a sentimental fashion, or Jane Austen writing a well-organized factorial program with a sly satirical streak.
If you’re a newbie programmer, this book will not help you learn how to write elegant JavaScript programs and ace whiteboarding interviews. But more self-assured coders may enjoy how this book treats programming as an art form, with JavaScript snippets that express individual style and voice rather than adhering to standard conventions.
Because everything can be done in so many different ways, JavaScript is very reflective of the writer. Croll beautifully displays this by showing what various programs would look like if written by different authors. In total, 25 different authors - from J.K. Rowling to Lewis Carroll - are divided up among 5 different programs. Background is given for each author, and it is explained why their code would look like it does. Many of the programs are almost unintelligible - especially for the authors that are known for being unintelligible. An expert level of JavaScript is needed to fully understand and appreciate each program. That is something that I don't have, so a bit of the effectiveness was lost on me.
The intro mentions the natural language nature of Javascript. I wonder if the book had been concieved a few years later if it would rather have been Python or Ruby - both of which are way more like human language than Javascript.
The book is fun and I mostly get it, but to truly get what the author is doing here, I think you would need to be a Javascript dev. The whole point is that the author is nerding out not only on the writing style of the authors they have chosen, but also converting that into Javascript coding styles. As someone who programmed in many languages, but hasn't touched Javasscript in the the mid-90s, a lot of the elegance of this book is lost on me.
That said, it's a fun read. I think because of the self-contained nature of the chapters and sections - chapters are focused on a specific classic programming problem (fibonacci sequence, factorials) and sections on authors - this would me a good coffee table book or bathroom book. Something you can read in bits and pieces whenever the urge would strike you. Otherwise, I imagine it could be finished in a session of an hour or two, depending on how much time you spent with the code examples.
This is what happens when a love for language in its most literary sense spills over into programming syntax. And the the oddities of Javascript lends itself well to these algorithmic flights of fancy. Angus Croll's passion for reading and Javascript are hard to miss. The illustrations are brilliant and the material providing background on each writer (Ernest Hemingway, David Foster Wallace, Jane Austin, Lewis Carroll, Tupac, etc.) is fantastic. I wanted to understand more about higher order functions and Sylvia Plath. This book targets an admittedly narrow audience, but it sure nails its target.
I s'pose a title such as 'if two dozen well-known authors wrote JavaScript' wouldn't be as catchy, but that's what the book demonstrates. It was short, it was enjoyable, it was different. I confess I didn't pay too much attention to the code, but the author's knowledge of literature as well as JavaScript is pretty deep and unique. I didn't care too much for the red on light-red typesetting - it was too gaudy for my taste. Recommended.
That’s said, for such a niche market, this is a work of art. It’s absolutely hilarious and dances the knife’s edge between pretentiousness and flippancy. I found myself getting upset at the supposed authors for writing the JavaScript the way they did, it was very convincing and the commentary is priceless.
Artig liten sak. Mer morsom enn lærerik. Hvert kapittel tar for seg en forfatter (litt fakta om forfatteren) og en implementasjon av et problem i JavaScript, skrevet i "stilen" til den forfatteren. Mye humor, og mye god litteratur.
Fun little read, and explains the styles of the different authors nicely. I've not read nearly enough classics, but the javascript solutions are all quirky and sufficiently different, which is fun as a programmer. I even learned some new things (horrible as they may be)!
Enjoyable. This was a gift and it was well chosen. I found it light hearted, comical and yet oddly educational. It makes me smile to think a twitter programmer wrote this.
A very clever and witty book that brings together two, what initially appear as fairly disparate, topics in a easy to read way. It also showed me how little I know of JavaScript!
A fun book that mixes literature with programming by examining JavaScript written in a style that is similar to various authors. Much funnier if you have read books by the discussed authors.