In Once Upon an Algorithm: How Stories Explain Computing, Martin Erwig aims to spread an interest in computer science by drawing parallels between processes of computation and the problem-solving stories found in popular culture, including the fairy tale Hansel and Gretel and the film Groundhog Day. While some of the content does demand close attention, the concrete examples make this generally an accessible and fun read, finds Esmeralda V. Bon.
Once Upon an Algorithm: How Stories Explain Computing. Martin Erwig. MIT Press. 2017.
Most of us enjoy listening to stories. They can serve as mnemonic devices as well as teach us about and perhaps even change our lives, lives which are increasingly fast-paced and much more digital than they once were. Whilst stories can have a transformative effect, computers have, in fact, changed how we live. For some, computers and computing may appear to involve difficult-to-understand, complex and abstract processes and terms. To this end, Martin Erwig, Professor of Computer Science at Oregon State University, has written his third book, Once Upon an Algorithm: How Stories Explain Computing.
In this book, he takes a more bottom-up approach, introducing concepts of computation and computer science to the general public one at a time, and linking these to the activities that we engage in throughout the day. By doing so, he aims to spread an interest in computer science and to motivate readers to learn more about this field. The main argument of this book is, then, that there are parallels between the processes of computation studied, tested and applied in computer science and the problem-solving actions we take on a day-to-day basis.
Throughout the book, Erwig references popular culture, including the fairy tale Hansel and Gretel, the movie Groundhog Day and the Harry Potter books. As such, this work delightfully differs from the standard introductory textbook in computer science as well as manuals designed to teach specific programming languages, such as the ‘For Dummies’ series (e.g. Data Science for Dummies; Coding for Dummies). Although the majority of these books do tend to clearly explain and introduce the most important concepts, they do not use such memorable examples.
That being said, these manuals typically offer exercises and opportunities for practically applying the material learned. This book serves a different purpose: its examples explain theory, and it should therefore rather be seen as an extensive, occasionally heavy, reference work with a glossary that could improve the theoretical knowledge and understanding of a motivated reader. It does not contribute towards skill-building.
Image Credit: (Michael Coghlan CC BY SA 2.0)
The start of the day and the book is reserved for the famous tale of Hansel and Gretel by the brothers Grimm. This story is used for introducing the key foundational concepts ‘computation’ and ‘algorithm’, which are of such importance that they feature in the morning routine. According to the fairy tale, Hansel and Gretel find themselves all alone in the woods, left by their parents in a time of raging famine. Wanting to find their way home, the siblings engage in a process of problem-solving. Hansel decides to drop the pebbles he has previously collected at intervals, and by revisiting these pebbles, following the created path step-by-step, Hansel and Gretel reach their parents’ home.
This solution could be made into an algorithm once written up in a computer or programming language: it involves a mechanism for stepwise finding one’s way from A to B, which can be used repeatedly. To be an algorithm, the solution – like a story – should also have an ending and lead to some resolution. Whereas in the fairy tale Hansel and Gretel do reach home in the end, where they are accepted with open arms by their grieving father, for the algorithm the solution is obtaining accurate results. In this case, the correct house is successfully reached.
In a later chapter, Erwig addresses the extent to which we spend our days habitually. If we have grown comfortable with folding a paper in a certain way so that it fits in an envelope, then we have grown accustomed to using a certain algorithm. However, if we choose to continue to repeat the action, then we require a description of this repetition and a control structure, such as the ‘loop’, to make sure that an operation does not run indefinitely. Erwig uses Groundhog Day to clarify how loops and control structures work.
In this film, a weather reporter called Phil Connors is made to continuously relive ‘Groundhog Day’. As Erwig explains, this is the day on which a groundhog – a type of rodent – is thought to predict when winter will come by choosing to come out or stay in his burrow. In his desperate attempts to break this cycle, Phil explores his actions. Surely, if he gets rid of Punxsutawney Phil, the groundhog, Groundhog Day should end? However, as it turns out, to leave the loop Phil would have to change his attitude towards the festivities and perhaps even life in general. Such terminating conditions are to be specified for each loop.
Next to the concepts of computation, the algorithm and the loop, Erwig also uses the story of Harry Potter for explaining how ‘types’ work. When we are finally sitting down to dinner, we would struggle eating soup with a fork rather than a spoon. This would be a type error: an error in the type of utensil used. Types have certain properties which distinguish them. Harry Potter-related examples are the difference between muggles and wizards and witches – the difference between Harry and his aunt Petunia – and the properties of Harry’s invisibility cloak compared to the other cloaks he owns. In this way, types help make sense of the world through classifying objects and thereby managing expectations for computation.
In the end, the content of this book, as well as the way it is structured, moving from one concept, theme or topic to another, could be repetitive. Admittedly, Erwig does provide some guidance in the introduction, indicating which sections would be relevant to read in which cases. His writing style does also appear geared towards the academic reader. A reader may find some parts of the book dry reading, exacerbated by the fact that it does not have a narrative arc and little plot. The book would specifically have benefited from a more elaborate and engaging writing style as well as an introduction and conclusion that briefly contextualise and describe the history and development of the discipline.
Overall, Once upon an Algorithm is recommended to anyone new to the field of computer science with an interest in learning about the theoretical basics of the field as well as its application to our lives. Some sections will require close attention from the reader, due to the complex nature of the matter at hand and the occasional heavily informational presentation of the content. However, the use of concrete examples as well as entertaining stories generally makes this book a fun and accessible read.
Esmeralda V. Bon is an ESRC-funded PhD student in Politics at the University of Nottingham, in collaboration with the Committee on Standards in Public Life (CSPL), located in the Cabinet Office. Her research focuses on the political communication of UK public office holders and civil society actors, with special attention for the strategic use, presence and absence of emotion and evidence. She tweets @EsmeraldaVBon
Note: This review gives the views of the author, and not the position of the LSE Review of Books blog, or of the London School of Economics.