Think Like a Programmer, by V. Anton Spraul
No Starch Press, San Francisco 2012

A review by Alec Edgecliffe-Johnson

V Anton Spraul’s “Think Like a Programmer” is, at its core, a guidebook for intelligent thought in the new digital age. Unlike most “how to program” manuals designed to instruct in the technicalities of programming, this is a volume that teaches the mental framework that underpins much of new technological creation. If we think of programming as a foreign language, an analogy which is inherently limited but useful in this particular instance, this book teaches grammatical principles, sentence structure and the rules that connect our current language to target languages generally. It leaves language-specific vocabulary, verb tenses etc. to other sources.

The framework taught is therefore universally applicable: the “programmer” mindstate can, and should, be generalized and skillfully applied to problem solving and creative pursuits beyond programming. The way of thought, therefore, belongs on a shelf in our minds alongside other systematic models, which we should be able to skillfully blend and apply to fit particular situations. Given the omnipresence of digital and machine-based technology in our lives and the necessity of understanding it, it’s likely that an increasing number of situations will warrant this particular model (or a hybrid model of it.)

To instruct his readers, Spraul outlines general principles of problem solving and then challenges us to use them to address a number of different programming puzzles. In applying the principles in different structural contexts, the reader gains a deep understanding of the basic commands that programmers have at their disposal and the way in which programs (and thus machines) are instructed to “think” and act. Thus he/she gains an understanding of both the underlying nature of digital technology and the principles upon which programmers craft it.

The foundational principles of problem solving are, at first glance, trivial:
1. Always have a basic plan and a clear direction
2. Restate the problem in a way that includes both constraints to action and possible actions. In this way the number of potential solutions is dramatically reduced.
3. Divide the problem into steps and look for connections between the steps
4. Start with what you know how to do
5. Reduce the problem by removing or adding constraints
6. Look for analogies between a particular problem (or component/step of a problem) and other problems you are familiar with
7. Experiment with different solutions
8. Don’t get frustrated

The true significance and applicability of these principles can only be grasped through repeated application in specific context, which is why the book has been designed as a workbook rather than a manual.

Although most of the puzzles in the book revolve around the application of computer code, Spraul begins his demonstration of the power of the methodological approach to problem solving with a number of “simple” problems. The first such problem involves a farmer, a rowboat, a fox, a hen and a bag of corn. The farmer must transport all the items to the far side of a river but can only take one item across at a time and cannot leave the fox alone with the hen or the hen alone with the corn. In order to solve it, one needs to break the problem down to its composite parts and strictly define the constraints and all possible steps/actions that are possible.

Constraints:
1. The farmer can only carry one item in the boat at a given time
2. The fox and hen cannot be left alone
3. The hen and corn cannot be left alone

Steps/Actions:
1. Row the boat from one shore to the other
2. If the boat is empty, load an item
3. If the boat is not empty, unload the item

By formalizing the constraints and then the actions, the “key” to the puzzle that is not initially stipulated is uncovered: the farmer can take items back to the initial shore after he has taken them across. From there the solution is simple: take the hen across, then return for the bag of corn, take the corn across and then return with the hen, leave the hen on the initial bank and take the fox across and, finally, return for the hen.

While the principles serve as a useful guide to problem solving, the command structures around which the puzzles in the book are designed reveal something about the “brain” of a computer. With a bit of googling alongside the outlined solutions, a non-technical reader with no previous programming knowledge can quickly attain a robust understanding of the basic tools from which a program is built. In other words he/she gains insight into the thought processes of a computer through tools like for, if, and while statements arrays, pointers and dynamic memory, classes, recursion and components. In this examination the reader also gains an intuitive understanding of the constraints that bind computer programs and “digital” thought.

When combined, the problem-solving principles and the command structures give the reader at least a minimal degree of digital literacy. This is of course not nearly enough to write the next blockbuster app but it is enough to read and understand simple commands and their purpose. We do not, after all, expect a kindergartener to write a novel; the ability to read at a lower level and write a simple paragraph is qualification enough of literacy.

The importance of the attainment of literacy by the kindergartener is self-evident, but why should we culture digital literacy? The ubiquity of digital technology bears with it an implicit challenge, a challenge to control our interactions with technology with skill, grace and understanding. Digital literacy is thus, to an ever-greater extent, a choice between being as a passive “taker” of the change in the world, or an active “maker.” If we fail to acknowledge the challenge we allow digital technology and its creators to control our interactions with it.

It is tempting to draw parallels between digital literacy and traditional literacy and to regard digital literacy as the “new” literacy of the 21st century. In doing so, though, we misinterpret the essence and potential of each. Traditional literacy remains a gateway to knowledge acquisition and an indirect channel for exerting influence. Digital literacy, on the other hand, is a means of navigation of the world and is a channel for more direct influence over the world. It allows us to shape our environments not through the fickle actions of man but through those of the predictable machine. Furthermore it equips us with a transcendental framework for thought and action that can be applied consciously or unconsciously. As Spraul makes clear, the benefit of thinking like a programmer, aside from technological creation, is the ability to navigate an environment saturated with digital technology and machines built around digital technology. It is a way of thinking that can allow us to direct ourselves through an increasingly complex world built on a set of rules that we are not naturally adapted to understand.

Machine action is, for the moment at least, predictably reflective of its inner programming and it lacks many of the inconsistencies and idiosyncrasies of human action (unless these inconsistencies are purposefully implemented.) However, while we are naturally equipped with tools to understand human action, (empathy, compassion, reasoning) many of us lack the mental models and knowledge to interpret machine action. The call for greater digital literacy then, is a call for the non-technical to join the programmers, if not in their craft than at least in their ability to understand the increasingly complex reality that they are creating.