Å·±¦ÓéÀÖ

Yevgeniy Brikman's Reviews > Code: The Hidden Language of Computer Hardware and Software

Code by Petzold Charles
Rate this book
Clear rating

by
1363537
's review

it was amazing
bookshelves: desert-island-reads

Every single person in tech should read this book. Or if you're just interested in tech. Or if you just want a basic appreciation of one of the most important technologies in human history—the computer.

This book contains the best, most accessible explanation I've seen of how computers work, from hardware to software. The author manages to cover a huge range of topics—electricity, circuits, relays, binary, logic, gates, microprocessors, code, and much more—while doing a remarkable job of gradually building up your mental model using lots of analogies, diagrams, and examples, so just about everyone should be able to understand the majority of the book, and gain a deep appreciation of what's really happening every time you use your laptop or smartphone or read this review online.

I wish I had this book back in high school and college. I've been coding for 20 years and I still found a vast array of insights in the book. Some of the topics I knew already, and this book helped me appreciate them more; others, I knew poorly, and now understand with better clarity; still others were totally new. A small sampling of the insights:

* Current is the number of electrons flowing past a point per second. Voltage is a measure of potential energy. The resistance is how much the substance through which electricity is flowing resists the passage of those electrons. The water/pipes analogy is great: current is similar to the amount of water flowing through a pipe; voltage is similar to the water pressure; resistance is similar to the width of the pipe. I took an E&M physics course in college and while I learned all the current/voltage/etc equations, I never got this simple, intuitive understanding of what it actually means!

* We use base 10 because we have 10 fingers; a "digit," after all, is just a finger (so obvious when you actually take a second to think about it!). Had we been born with 8 fingers, like most cartoon characters, we'd probably use base 8 math. Computers use base 2 because building circuitry based on two states—the presence or absence of voltage (on and off, 1 or 0)—is much easier than circuitry based on ten states.

* The notation we use in math is essential. It's not about looking pretty or not, but actually making the math easier or harder. For example, addition and subtraction is easy in Roman numerals but multiplication and division are much harder. Arabic numerals make multiplication and division much easier, especially as they introduce a 0. Sometimes in math, you switch to different coordinate systems or different geometries to make solving a problem easier. So it's no surprise that different programming languages would have the same properties: while any language can, in theory, solve the same problems as any other, in practice, some languages make certain problems much easier than others.

* This book does a superb job of showing how logic gates (AND, OR, etc) can be built from simple physical circuits—e.g., from relays, which are much easier to imagine and think about than, for example, transistors—and how easy it is to do math with simple logic gates. I remember learning this back in college, but it still amazes me every time I see it, and with the crystal-clear examples in this book, I found myself smiling when I could picture a simple physical circuit of relays that could do arithmetic just by entering numbers with switches and passing some electricity through the system (e.g., to add, you have a sum and a carry, where the sum is an XOR and the carry is an AND).

* The explanation of circuits that can "remember" (e.g., the memory in your computer) was superb and something I don't remember learning at all in college (how ironic). I love the idea that circuits with memory (e.g., latches) work based on a feedback mechanism: the output of the circuit is fed back into the same circuit, so if it gets into one state (e.g., on, because electricity is flowing through it), that feedback mechanism keeps it in that state (e.g., by continuing to the flow of electricity through it), effectively "remembering" the value. And all of this is possible because it takes a finite amount of time for electricity to travel through a circuit and for that circuit to switch state.

* The opcodes in a CPU consist of an operation to perform (e.g., load) and an address. You can write assembly code to express the opcodes, but each assembly instruction is just a human-friendly way to represent an exactly equivalent binary string (e.g., 32 or 64 binary digits in modern CPUs). You can enter these opcodes in manually (e.g., via switches on a board that control "on" and "off") and each instruction becomes a high or low voltage. These high and low voltages pass through the physical circuitry of the CPU, which consist of logic gates. Based purely on the layout of these logic gates, voltage comes out the "other end," triggering new actions: e.g., they may result in low and high voltages in a memory chip that then "remembers" the information (store) or returns information that was previously "remembered" (load); they may result in low and high voltages being passed to a video adapter that, based on the layout of its own logic gates, results in an image being drawn on a screen; or they may result in low and high voltages being fed back into the CPU itself, resulting in it reading another opcode (e.g., perhaps from ROM or a hard drive, rather than physical switches), and repeating the whole process again. This is my lame attempt at describing, end-to-end, how software affects hardware and results in something happening in the real world, solely based on the "physical layout" of a bunch of circuits with electricity passing through them. I think there is something magical about the fact that the "shape" of an object is what makes it possible to send emails, watch movies, listen to music, and browse the Internet. But then again, the "shape" of DNA molecules, plus the laws of physics, is what makes all of life possible too! And, of course, you can't help but wonder what sort of "opcodes" and "logic gates" are used in your brain, as your very consciousness consists entirely of electricity passing through the physical "shape" of your neurons and the connections between them.

There are a few places the book seems to go into a little too much detail—e.g., going over all the opcodes of a specific Intel CPU—and a few places where it seems to skip over all the important details—e.g., the final chapter on modern software and the web—but overall, I have not found another book anywhere that provides as complete of a picture of how a computer works. Given the ubiquity of computers today, I'd recommend this book to just about everyone. It'll make you appreciate just how simple computers really are—and how that simplicity can be used to create something truly magical.





As always, I've saved a few of my favorite quotes from the book:

A computer processor does moronically simple things—it moves a byte from memory to register, adds a byte to another byte, moves the result back to memory. The only reason anything substantial gets completed is that these operations occur very quickly. To quote Robert Noyce, “After you become reconciled to the nanosecond, computer operations are conceptually fairly simple.�

The first person to write the first assembler had to hand-assemble the program, of course. A person who writes a new (perhaps improved) assembler for the same computer can write it in assembly language and then use the first assembler to assemble it. Once the new assembler is assembled, it can assemble itself.
22 likes ·  âˆ� flag

Sign into Å·±¦ÓéÀÖ to see if any of your friends have read Code.
Sign In »

Reading Progress

August 11, 2014 – Shelved as: to-read
August 11, 2014 – Shelved
Started Reading
January 19, 2018 – Finished Reading
February 2, 2024 – Shelved as: desert-island-reads

Comments Showing 1-2 of 2 (2 new)

dateDown arrow    newest »

Peter Perhac It’s still sitting on my shelf. Colleague recommended this book so I bought it. Now when I see your review I really have no excuse not to read it. 🙂


message 2: by Chandan (new) - added it

Chandan Sinha Awesome review! I agree with everything you wrote. This book was marvellous and something I had always subconsciously searched for ever since I came to know about computer systems. I just added a review of my own but I found yours to be pretty comprhensive and elegant.


back to top