[Note: This is a sample of my upcoming book Brown Dogs and Barbers. Please be aware that this text is subject to change and that diagrams are only placeholders. If you’d like to see this book become a fully illustrated and professional book, why not consider donating?]
Update: This sample is now slightly out of date. For a sample of the published book, please see the About Page.
I’d like to begin this book about computer science by asking you about your toaster. If I asked you to tell me how your toaster worked, I bet you’d have no trouble coming up with a decent explanation. Initially, you might claim you have no idea, but I’m sure a moment’s thought would yield a good description. Even in the worst case, you could actually look inside a toaster and deduce what was happening. Perhaps then you’d be able to tell me all about how electricity causes the filaments to heat up and that heat radiates onto the bread or the crumpet or whatever, causing it to cook.
If I were to ask about how a car worked, that might be more challenging. Again, you might instinctively feel that a car’s workings are a mystery to you. But even then, if you stop and think about it, you might recall a few vague terms that help out. Perhaps you could tell me about how petroleum is stored in the car’s tank and when you press the footpedal, the fuel is drawn into the engine where it’s ignited. Then you’d go on and tell me that this action drives the pistons… or something… and they turn the… I think it’s called the crankshaft… which is connected to the wheels and makes them turn. That’s what I would say anyway, and I know virtually nothing about how cars actually work.
I’m guessing all this without even knowing you, your occupation or your interests. True, you might be an engineer or a physicist for all I know, and able to give better explanations, but the chances are that you’re not. My point is, even if you have only the merest passing interest in science and technology, I’m confident that you comprehend things like toasters and cars enough to give half-decent explanations of them. Understanding things like these comes partly from school learning where, even if you sat spaced out during physics lessons, you still picked up some of that stuff about electricity and internal combustion engines. And let’s not underestimate how ingrained on our popular consciousness these concepts are. The people around us talk about the workings of everyday technical items all the time, so some of it is bound to stick with us whether we realise it or not.
But computers are different. Many of us haven’t got the first clue how computers work. Think about it. Could you tell me how the individual components in your computer work together? Could you even name any of the components? I’m certain some of you could, but I’m just as sure that a lot more people couldn’t even begin to explain a computer. To some, it’s a kind of magic box that sits under the desk and somehow draws letters and images on the monitor screen at breathtaking speed.
Let’s get one thing straight: I wouldn’t blame you for being unable to offer an explanation, because there are several reasons why you shouldn’t be expected to know about computers. One very important reason, again, is schooling. In many countries, computer science is not taught as part of general education. In my own country of birth (the United Kingdom), computing education has for many years meant nothing more than learning how to use word processors and spreadsheets; important skills to be sure, but this is definitely not computer science, a topic that studies at a fundamental level how to use mathematical principles in the solving of problems. The great majority of children leave school having learned to be passive users of computers at the most and many people are currently asking why such an important area of knowledge is absent from the curriculum.
The mystery surrounding computers is a problem that’s only becoming worse over time. When computers first arrived they were monstrous things bigger than a family-sized fridge and kept in huge, environmentally-controlled rooms. Their job was usually to carry out boring tasks like process tax returns and payrolls; tasks that anyone could do by hand, albeit a lot slower. They had banks of flickering lights that lit up when the machines were “thinking”; spools of tape mounted on the front spun around, indicating that the computer was looking in its databank; some were even partly mechanical, clicking and tapping uproariously when the numbers were being crunched. Yes, they were still mysterious — but today it’s even worse.
Computers are no longer just mysterious — they’re magical.
Today’s computers are a million light years ahead of their early ancestors. Nowadays they’re small, sometimes able to fit into the palm of your hand. How can something so tiny do such impressive things? They’re also ubiquitous, having gone far beyond their original, humble number-crunching duties until they organise every aspect of our lives. As a result they’ve become utterly unknowable. Today’s computer is an impersonal black box that gives no hint as to its workings. Of course, there’s a user interface that allows us mere humans to operate the computer, but one main purpose of a modern user interface is actually to hide the internal workings of the machine as much as possible. There are few external indicators about what’s really happening inside. Without moving parts (apart from the cooling fan, which I assure you performs no calculations) and with internal components that give no visible clue as to what they’re doing, it’s become impossible to try and deduce how a computer works by examining it. So advanced and unknowable have computers become, they may as well operate on principles of magic.
But there are genuinely knowable principles upon which computers operate. We find things that pump, rotate or burn easier to understand, because physical principles are more intuitive to us. In contrast, the driving principles behind computers are mathematical and thinking in these terms comes harder to humans. There are some physical principles involved, of course. Your computer contains various things —
circuit-boards, wires and chips — which all function according to good old-fashioned physics. But (and I don’t mean this to sound dismissive), those are merely the computer’s hardware. In computer science, there is a sharp and critical distinction between the physical machinery that performs the work (the hardware) and the mathematical principles which allow it to do anything meaningful. These principles make up the field of computer science. In theory, you can build computers out of all sorts of weird and wonderful parts, be they mechanical, electronic, or even water-powered. Yet, however a computer is implemented, it must work according to the principles of computer science in the same way that every car’s internal combustion engine, as varied as they are, all work according to the relevant laws of physics.
Hardware gets mixed up with the field of computer science. I’m pretty laid back about that, but some purists like to emphasise the strict division between the machinery and the principles. Roughly speaking, this corresponds to a separation between hardware and software. Software, a word I’m sure you’ve heard before, is the collection of programs which computers run and the concept of a program goes to the heart of computer science. Unfortunately, programs are a little hard to define, but rest assured that you’ll come to understand what a program is over the course of this book. What makes them tough to penetrate is that they’re nebulous, abstract things rooted in mathematics, a subject that’s a sort of parent to computer science. Programs have numerous legacies through this inheritance. Like mathematics, programs don’t really exist in a physical sense. They’re conceptual things, ideas that exist in programmers’ minds which are only given substance after they’re written down.
This inheritance from mathematics explains many things. It explains why programs look like jumbles of mathematical formulae. It explains why computer science attracts so many nerdy folks who are good with numbers. And it explains why programmers count up from 0 instead of 1 like the rest of the human race. Maybe you’ve noticed that? You might look through some of the programs on your computer and find a new one labelled version 1.0 . Why 1.0 ?
OK, you might say, after a program is updated the author appends a number to the version to make it clear. After the initial version is updated several times we progress through versions like 1.4 to 1.5 to 1.6 and so on. I get that. But why start at 1.0 ? Why not 1.1 ? And why, when I upgrade to the second version, is that called version 1.1 ?
You’d also find this peculiarity were you to read through the contents of a computer program. If you watch a race on TV, then at the end you’d say that the winner came in position 1, the runner-up in position 2 and so on. If you ask a programmer to write a program for processing the race, the results would begin with the winner assigned position 0 instead and the runner-up in position 1. To a programmer, the hero is a zero.
Counting up from zero, which instinctively seems unnatural, actually simplifies matters when you deal with lists of things. In these cases, counting up from 1 can cause confusion. For instance, have you ever stopped to think why the years of the twentieth century all began with 19 and not 20 ? It’s something that often trips up little kids (and occasionally big ones too). Why was the year 1066 part of the eleventh century and not the tenth?
To explain, let’s look at an example of counting up from 0, because we all do that occasionally whether we realise it or not. In some parts of the world, the bottom floor of a building is called the ground floor and the next one up is the first floor. In this case, the ground floor could just as easily be called the zeroth floor. Similarly, when programmers refer to specific items in a list (which they do a heck of a lot), they often need to calculate the position of an item in that list by offsetting it from a base position. This base item is labelled number 0. Working out a position when a list is arranged like the floors in a building makes things a little simpler. Floor 3 (or the third item) is three above the ground floor (or zeroth item). If the ground floor were floor 1, then the third floor would be two above the ground floor. This is visualised in Figure 1. We count centuries similarly to the left-hand building. Because we count centuries up from the one (the years 1 to 100 were the first century, not the zeroth century), we then have to remember that centuries don’t match with the years within them. It’s only a small confusion, but working out positions in a list is done so often that little hiccups like this can actually cause more problems than you think.
With this explanation, you’ve hopefully just learned something new about computer science. I know it’s only trivial, but nevertheless it shows you something about the subject and explains why that something is the way it is. This example is just the tip of the iceberg, so there’s much more complex and interesting stuff still to come. Computers are complex things, more so than any other machine we’re likely to use on a daily basis. Unfortunately, they remain mysterious to many people. For many of us, our relationship with computers is one of bemusement, frustration, and fascination, all experienced at arm’s length. We sometimes even find ourselves as the servile member in the relationship, desperately reacting to the unfathomable whims of our computer trying to make it happy. This is not the best state of affairs to be in if we’re going to be so reliant on them in our everyday lives. It doesn’t have to be this way. If our relationship with computers is sullied by their mysteriousness, the answer is simple: learn more about them. And I don’t mean learn how to make spreadsheets.
To understand what’s going on in that magic box beneath your desk, we’ll look in this book at the science behind it.
This book presents you with the core ideas of computer science. By reading them you will learn about the subject’s history, its fundamentals and a few things about its most pertinent protagonists. Understanding them will help to demystify the machine. Each chapter can be read as a self-contained unit, but nevertheless, they have all been written together in a way that reading from start to finish is like a story. They vaguely follow a chronology and each chapter builds gently on preceding ones. It’s your choice.
However you choose to read it, this book will take you from the earliest beginnings of mechanical computation and show you how we arrived at today’s world of the magical and ubiquitous electronic computer. You will learn of the monumental problems that faced computer scientists at every stage. You will see how they developed ingenious solutions which allowed the field to progress. And you will observe how progress leads to both new opportunities and new problems.