Foundations of ComputingDeeper

Kayavak / Foundations of Computing / CS·01 Start Here: Computers, Programs and Your Toolbox / Deeper

Deeper · Foundations of Computing

Start Here: Computers, Programs and Your Toolbox

The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.

Why does this exist?

Before stored programs, "programming" a computer meant rewiring it. ENIAC (1945) was set up for each new problem by plugging cables and setting switches, which could take days. The idea that changed this was to keep the instructions in the same memory as the data, so a new program was just new contents of memory. John von Neumann's First Draft of a Report on the EDVAC (1945) described that design; the Manchester Baby ran the first stored program in June 1948 and Cambridge's EDSAC began regular service in 1949.

Once a program is data, other programs can produce it. That is the whole lineage of this chapter: assemblers turned mnemonics into machine code, compilers (Grace Hopper's A-0 in 1952, FORTRAN in 1957) turned formulas into instructions, and operating systems loaded and ran programs for you. The terminal descends from the teleprinter: a keyboard and a printer wired to a machine, which is why we still say "TTY" and why programs read and write streams of text. Unix (1969 onwards) made that text interface composable: small programs, standard input and output, and pipes between them.

The mental model

Try it yourself first: write your own model in the Mental Model Explorer, then compare.

A computer is a machine that follows a list of very simple instructions, extremely fast, on numbers in memory. Everything else is a layer of programs that make that useful.

Question Answer
What is it? A processor that repeats: fetch the next instruction, do it, move on; plus memory that holds both instructions and data
What problem does it solve? Doing any well-specified procedure on information, without rebuilding the machine for each procedure
Parts Processor, memory, storage, input and output devices; above them the operating system, then your programs
How it works Your source text is translated (compiled or interpreted) into instructions; the OS loads them into memory and starts them as a process
Assumptions Instructions are exact and unambiguous; the machine does what they say, not what you meant
When they change Give a program ambiguous instructions and it still picks one meaning: the bug is the gap between the two
Where the model fails Real machines run many programs at once, reorder work internally and fail physically; later chapters add these
Related ideas Algorithms (ch04) are the procedures; operating systems (ch08) share the machine; compilers (ch10) translate

What if?

What if programs couldn't be stored in memory?

Reason it through, then open

Every change would be a hardware change, so there would be no software industry as we know it: no downloads, no updates, no compilers (a compiler's output is a program stored as data), no operating system loading your code. Machines would be built for one job, like a calculator or a loom. The stored-program idea is what made a general machine cheap to repurpose.

What if the terminal had no separate error stream?

Reason it through, then open

Errors and results would arrive mixed in one stream. Redirect a program's output to a file and its error messages would land in that file too, silently corrupting the data, and you would see nothing on screen. Pipes would pass error text into the next program as if it were input. Unix gave every program a second output, standard error, so that results can travel down a pipe while problems still reach a person.

Where the boundary is

Aspect Program Process
What it is A file of instructions (source or machine code) A running instance of a program, with its own memory and state
How many One file on disk Any number at once, from the same file
Lives Until deleted From start to exit
Has Instructions Instructions plus memory, open files, a position in the code
Confused because We say "the program is running" Running is what turns a program into a process

How sure are we?

Claim How it's known Where from
Stored-program design: instructions and data share memory Historical von Neumann's EDVAC report (1945); Manchester Baby, 1948
A computer only follows instructions exactly Model True of the instruction set; hardware faults and some deliberate randomness are the exceptions
Every program's results go to standard output and errors to standard error Convention Unix design; programs can ignore it, and some do
"Compiled" and "interpreted" are two kinds of language Simplification It's a property of implementations, and most real ones mix both (chapter 10)

Still open

How best to teach programming is genuinely argued about: which first language, whether to start with the machine or with abstractions, how much to rely on tools that write code for you. This book's answer (start from the machine, compare several languages) is one defensible choice, not a settled result.

What would change your mind? If you found a task a computer did that no list of instructions could describe, the model "a computer follows instructions" would be wrong. Turing's 1936 paper is the argument that any mechanical procedure can be written as such a list.

Recall

Why was the stored-program design such a big change?

A new program became new memory contents rather than new wiring, so machines could be repurposed instantly and programs could produce other programs.

What's the difference between a program and a process?

A program is the instructions in a file; a process is one running instance of it, with its own memory and state.

Why do programs have separate standard output and standard error?

So results can be redirected or piped without error messages mixing into them, while errors still reach a person.

Is "compiled versus interpreted" a property of a language?

No, of an implementation; many implementations mix both.

Reflect

Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.