review: Data Structures and Algorithms with JavaScript
¶ by Rob FrieselMike McMillan’s Data Structures and Algorithms with JavaScript (O’Reilly, 2014) uses JavaScript as a vehicle for introducing a number of fundamental computer science concepts. It reminds me a little bit of Tom Stuart’s Understanding Computation 1 — that is, it’s a book about CS topics that targets people without a CS background. One might consider both books to be a gentle introduction to computer science, or “computer science for the layperson”. 2
At a high level, McMillan walks us through some of these different data structures (e.g., sets, binary trees) and algorithms (binary search, quick sort). These are topics that we might have encountered in introductory computer science courses 3 — he just happens to have chosen JavaScript as the illustrative language here. And there are some good reasons for choosing JavaScript: it is fairly ubiquitous, and it’s comparatively easy to start programming with JavaScript as opposed to many other languages. There’s also this latent assertion that there are many people who are doing professional software development (with JavaScript) who otherwise do not have CS backgrounds. 4
To this point, McMillan is largely successful. He is able to demonstrate how to implement these data structures and algorithms using JavaScript, even if it isn’t always clear why we would use JavaScript. He clearly articulates the traditional use-cases for each of the data structures and algorithms, but sometimes we’re left wondering why JavaScript? with respect to solving a particular problem (e.g., as opposed to a language that already has that data structure built in 5). Also, some of his implementations appear to duplicate built-in objects (e.g., his HashMap
arguably overlaps with JavaScript’s built-in Object
) or else they’re implemented… strangely? (E.g., his Dictionary
implementation uses an Array
under the hood for no good reason. 6)
That being said, McMillan does a great job of explaining each data structure, what shape they are, why you would want to use one over another, and how they align with certain types of problems. (Same goes for his discussion of search and sort algorithms.) However, despite how strong these discussions are, it also seems to go against the current trend in JavaScript development. As I read through many of these chapters, I thought to myself: “Wouldn’t you just use a function for that?” Granted, the OO approach gives us those functions (as methods) just beneath the façade of the object itself — but still, those thoughts were there: Wouldn’t you just use a function? and Why do this in JavaScript when there are other languages that have first-class support for this?
Overall, I enjoyed McMillan’s book. I found it was a good introductory level instructional text for some of these CS concepts (even if the choice of JavaScript is a bit of a novelty) — but I wouldn’t consider it a practical manual of what to do “in the field”. If you’re doing software development in JavaScript and you’re trying to fill in the gaps of your computer science background, I would recommend this.
Disclosure: I received an electronic copy of this book from the publisher in exchange for writing this review.
- I reviewed Understanding Computation last year. It was the first book that helped me to really understand the differences between “computer science” and “software engineering”.[↩]
- As condescending as it sounds, there were a couple of times where I thought a good subtitle for it might have been something like “A Field Guide to Real World Computer Science”.[↩]
- …had we made it all the way through our introductory computer science courses. Which… you know… I didn’t.[↩]
- Long-time readers of this blog will notice the restraint I’m using here by not invoking what I’ve come to think of as “Miraglia’s Assertion”. Or at least resisting the urge to put that in the main body text.[↩]
- I deal with sets fairly often in my work and say what you will about Groovy but at least I don’t have to monkey-patch in support for sets.[↩]
- He says something in the text about using an
Array
because we want to output theDictionary
keys in alphabetical order, but then he winds up usingObject.keys
for that anyway and I just frowned and scratched my head a whole bunch there.[↩]
Leave a Reply