Professional Documents
Culture Documents
TouchOfClass Chapter1 PDF
TouchOfClass Chapter1 PDF
1
The industry of pure ideas
There’s a difference between our machines and theirs. If you drop one of
their machines, it will hurt your feet. Ours won’t.
Since one cannot operate a pure idea you will need some tangible,
material support to operate programs or, using the more common terms, to run
or execute them. That support is another machine: a computer. Computers and
related devices are called hardware, indicating that — although they’re
getting ever lighter — computers are the kind of machine that will hurt your
feet. Programs and all that relates to them are by contrast called software, a
word made up in the 1950s when programs emerged as topic of interest.
Here is how things work. You dream up a machine, big or small, and
describe your dream in the form of a program. The program can then be fed
into a computer for execution. The computer by itself is a general-purpose
machine, but when equipped with your program it becomes a specialized
machine, a material realization of the immaterial machine that you defined
through your program.
6 THE INDUSTRY OF PURE IDEAS §1.1
The person who writes the program — “you” in the previous paragraph
— is predictably called a programmer. Others, whom we call users, can then
run your program on your computer, or theirs.
From idea to
A writes a results
Program
which a
programmer
User
runs on a
Computer.
If you have ever used a computer, you’ve run some program, for example to
browse the Web or play a DVD, so you already are a user. This book should
help you make it to the next step: programmer.
Cynics in the software industry pronounce “user” as “loser”. It’s one of the goals
of this book that users of your programs will pronounce themselves winners.
Well, all right, it is one of two limits; we don’t like to mention the other
in genteel company, but you will likely encounter it before long; it is your own
fallibility. Nothing personal: if you are like the rest of us, you make mistakes.
Lots of mistakes. In ordinary life they are not all harmful, as most human
activities are remarkably error-tolerant. You can press your fork a little too
intensely, drink your water a little too fast, push the accelerator a little too
hard, use the wrong word; this happens all the time and in most cases doesn’t
§1.1 THEIR MACHINES AND OURS 7
prevent you from achieving what you wanted: eat, drink, drive, communicate.
But programming is different! At a dazzling speed — hundreds of millions of
basic operations per second — the computer will run your machine
description, your program, exactly as you prepared it. The computer doesn’t
“understand” your program, it just runs it; the slightest mistake will be
faithfully carried out by the machinery. What you wrote is what you get.
If you have used computers you know that they do not always react the
way you like. It doesn’t take very long to experience a “crash”, that state in
which it seems everything goes away and execution stops. But except for the
rare case of a hardware malfunction it’s not the computer that crashed; it’s a
program that did not do the right thing, and behind the program it’s a
programmer who did not foresee all possible execution scenarios.
In the next chapters we are going to jump right into program development.
Initially we will not need too much detailed knowledge about computers, but
let’s see their fundamental properties, as they set the context for the
construction of software.
What computers do
• Storage and retrieval
• Operations
• Communication
General organization
The previous definition yields the basic schematic diagram for computers:
Communication Components of
devices a computer
Rest system
of the Processors
world
Memories
Some people will tell you that “data” should only be used in the plural, because it’s
originally the plural of “datum”. Thank them for the kindness of their advice and
disregard it cheerfully. Unless they intend to continue the conversation in Latin,
their linguistic data is obsolete.
Information is what you want: the day’s headlines, a friend’s picture,
background on someone you’ll be meeting. Data is how it’s encoded for
the computer.
As an example, the MP3 audio format, which you may have used to listen
to music with the help of a computer, is a way to encode enough information
about a piece of music into data that can be stored in a computer, exchanged
across a network, and sent to an audio device so that it will replay the music.
The data will be stored in memory. It is the task of the communication
devices to produce data from information coming from the world out there, store
it in memory, and when the processors transform this data or produce new data,
to send it out to the world so that it will understand it as information. Adapted to
show the functions performed, the original picture looks becomes this:
Information Information Information
and data
processing
Input Output
Data Data
Process
Data
The right-to-left arrow suggests that the process is not just one-way but repetitive,
with information being repeatedly fed back to yield new results.
§1.2 THE OVERALL SETUP 11
Computers everywhere
Computers:
desktop (a);
(a) laptop (b); PDA
(c); processor to
be embedded
(c) (d).
(d)
(b)
The computers you will use for exercises of this book are still of the
keyboard-mouse-terminal-box kind, but keep in mind that software techniques
have to cover a broader scope. Software for embedded systems must satisfy
very high quality requirements: malfunctions in (for example) brake-control
software can have terrible consequences, and you cannot fix them — as you
would for a program running on your laptop — by stopping execution,
correcting the error, and starting again.
Definition: Memory
A memory is a device for storing and retrieving data and programs.
We’ll often encounter the following terms reflecting this division of tasks:
A deck of
punched cards
Touch of history:
It’s all in the holes
Aerospace industry old-timers tell the story of the staff engineer who, in an (Possibly apocryphal,
early rocket project, was in charge of tracking the weight of everything that but a good story still.)
would get on board. He kept pestering the programmers about how much
the control software would weigh. The reply, invariably, was that the
software would weigh nothing at all; but he was not convinced.
One day he came into the head programmers’ office, waving a deck of
punched cards (the input medium of the time, see the picture): “This is the
software”, he said, “Didn’t I tell you it had a weight like everything else!”.
This did not deter the programmer: “See the holes? They are the software.”
1-E EXERCISES
1-E.1 Vocabulary
Give a precise definition of each of the terms in the above vocabulary list.
You know about alphabetical order: the order in which words are listed in a
dictionary or other “alphabetical” list. Alphabetical order specifies, of two
different words, which is “before” the other. For example the word sofa is
before soft, which itself is before software.
The question you are asked in this exercise is simply:
That is to say, define alphabetical order. This is a notion that you undoubtedly
know to apply in practice, for example to look up your name in a list of
candidates to an exam; what the exercise requests is a precise definition of this
intuitive knowledge, of the kind you might need for a mathematical notion —
or for a concept to be implemented in a program.
To construct your definition you may assume that:
• A word is a sequence of one or more letters. (It’s also OK to use “zero or
more letters”, that is to say accept the possiblity of empty words, if you
find this more convenient. Say which version you are using.)
• A letter is one among a finite number of possibilities.
• The exact set of letters doesn’t matter but for any two letters it is known
which one is “smaller” than the other. For example, with letters of the
Roman alphabet, a is smaller than b, b is smaller than c and so on.
If you prefer a fully specified set of letters, just take it to include the twenty-six
used in common English words, lower-case only, no accents or other diacritical
marks: a b c d e f g h i j k l m n o p q r s t u v w x y z, each “smaller” than the next.
The problem calls for a definition, not a recipe. For example, an answer of the
form “You first compare the first letters of the two words; if the first word’s
first letter is smaller than the second word’s first letter then the first word is
before the second, otherwise...” etc. is not acceptable since it is the beginning
of a recipe, not a definition. A proper definition might start: “A word w1 is
before a word w2 if and only if any of the following conditions holds: ...”.
Make sure that your definition covers all possible cases, and respects the
intuitive properties of alphabetical ordering; for example it is not possible to
have both w1 before w2 and w2 before w1.
About this exercise: The purpose is to apply the kind of precise, non-operational
reasoning essential in good software construction. The idea is borrowed from a
comment of Edsger Dijkstra, a famous Dutch computer scientist.