Book Reviews

Code: The Hidden Language of Computer Hardware and Software by Charles Petzold

ISBN-13: 978-0735611313
Publisher: Microsoft Press
Pages: 400

I was fortunate enough to start my coding adventures back in a day where assembly languages were still a thing for application programming. I taught myself some of the basics on my Commodore 64, programmed micro controllers at the university, and started my professional career by writing assembly for an ancient 16-bit safety critical system for the railway industry. As such, I got a bit closer to the metal than I do these days. However, I still didn't have a solid understanding of what really happens in a computer. That's why I turned to Code: The Hidden Language of Computer Hardware and Software. Because what we have here is brilliant. Charles Petzold takes us on a ride from flashlights and telegraph relays all the way to classic microprocessors like the Intel 8080 and Motorola 6800. Along the way we get to actually implement real computers, RAM, controllers for peripherals, and even basic persistence mechanisms.

From Simple Building Blocks to Complex Systems

The underlaying idea in this book is that we can construct machines that are, on a theoretical level, computers by combining simple building blocks. Charles Petzold choses the humble electromagnet as our main building block. Using relays, we learn to build logical gates like AND, OR and NOR. From there we get to combine the different gates to create machines that automate addition and subtraction. Sure, the machines may not have the most practical UI as we have to enter binary numbers by flipping switches. But it's a simple start that introduces the fundamental ideas behind how computers work. Later in the book, Charles Petzold introduces the transistor in place of the relays. It's fascinating to see how all the fundamentals we learned while assembling relays still apply.

The book has a nice pace that gradually walks us through the construction of increasingly complex hardware where the next step builds on the previous one. For example, once we've learned to build logical gates out of relays, we see how we can wire two NOR gates into an information retaining circuit. That is, we can now represent state. Later constructions, like the RAM memory, are conceptually harder, but it's still striking how simple these initial constructions are. And that's kind of the beauty: at its fundamental level, a computer is built out of simple parts that are easy to understand and reason about in isolation. Like so many other systems, it's the interactions between all those building blocks that create complex behavior. I'd like to draw a parallel to Conway's Game of Life. The Game of Life has ridiculously simple rules, yet the emerging system behavior is anything but simple. The individual cells in Game of Life relate to the observable behavior of the simulation in just the same way logical gates relate to computer systems. I also think that the same properties apply to software systems; we can have simple building blocks like cohesive functions or classes that are easy to reason about, yet when we combine them, there's no way for us to hold the interactions and emerging behavior in our head (and that's why bugs arise).

A Computer from the Nineteenth Century

This book is full of insights. A few chapters into the book, a surprising revelation occurs. And I say surprising, because it's so obvious in retrospect: all parts we've been using so far were invented more than 130 years ago! That means, we could have constructed a computer in the nineteenth century. However, no one made the connection between simple switches and boolean algebra back then. This is something that's true of most innovations. Groundbreaking ideas and innovations look obvious in retrospect. But that's only because the choices have been made for us. We tend to forget about all the possible paths forward and how a now obvious construction combined ideas from previously unrelated fields. This book includes a great example on this as it introduces the iconic Charles Babbage (1792-1871). Babbage was one of the true pioneers in the field of computing, dedicating much of his life to the construction of an Analytical Engine. Babbage failed to complete his project, which was an entirely mechanical design. What's interesting though, is that Babbage was in correspondence with George Boole and knew about boolean algebra. So even though computing occupied Charles Babbage's mind, and even though he corresponded with Boole, Babbage still failed to make the connection that something as simple as a telegraph relay provided the key ingredient to a computer. It's fascinating to think what could have been, had the computer been invented 150 years ago. I'm not sure the world would have been a better place.

Code is a wonderful book that I recommend to every programmer. Sure, the book is 15 years old, which means it doesn't cover the multi-core revolution or the increased importance of CPU caches. This doesn't detract any of the value - everything you'll learn is still relevant - it just means that I'd love to get Charles Petzold's take on those topics too. Code is a solid introduction to computer hardware that also includes interesting mini-biographies on some of the pioneers behind the computing technology we've come to know today. The result is a masterpiece that I highly recommend.

Reviewed May 2016