On this page
Every time you write a line of Python and press run, a program translates your words into steps the machine can follow. In the early 1950s colleagues told Grace Hopper that computers could only do arithmetic, and programmers had to write in the machine's own code. Hopper, a mathematician and naval officer, disagreed and built the tools to prove them wrong. This post covers her life, what a compiler does, the true story of the famous computer "bug", a short exercise in compiling by hand, and what a student can take from her way of working.
Who was Grace Hopper?
The MacTutor biography gives her dates as 9 December 1906, New York, to 1 January 1992, Arlington, Virginia. She studied mathematics and physics at Vassar College, graduating in 1928, and Yale University records her master's degree in 1930 and PhD in mathematics in 1934. She taught mathematics at Vassar before joining the US Naval Reserve in 1943.
The Navy sent her to Harvard, where from 1944 she worked with Howard Aiken on the Mark I computer; MacTutor describes her as the third person to program it. She later moved to the Eckert-Mauchly Computer Corporation to work on UNIVAC, and stayed through its takeover by Remington Rand and then Sperry.
What really happened with the first computer bug?
A Navy photograph record, NH 96566-KN from the Naval History and Heritage Command, describes a moth found trapped in Relay 70, Panel F, of the Harvard Mark II on 9 September 1947. The operators taped it into the log with the note "First actual case of bug being found." Two details are worth noticing. The record credits the operators, not Hopper herself, though she worked on the Mark II team. And the word "actual" shows that engineers already called faults bugs; the joke was that, for once, the bug was a real insect.
What is a compiler, and why did 1952 matter?
A compiler is a program that translates instructions written in one language into another, usually into the step-by-step code a machine runs. Yale's account says that in 1952 Hopper and her team developed the first computer language compiler, which made it possible to write programs for many computers rather than a single machine. The White House citation for her Presidential Medal of Freedom, awarded posthumously in 2016, says she "created the first compiler, which translates source code from one language into another".
Her 1952 paper, The Education of a Computer, is generous about where the ideas came from. She credits Aiken for the idea of a library of routines, John Mauchly for the principles of "short-order code", and Maurice Wilkes for a book on the subject. According to MacTutor, she then helped build Flow-Matic, the first English-language data-processing compiler, which became a foundation for the language COBOL in 1959.
Worked example: compile a formula by hand
Imagine a simple machine with one register, the accumulator, and five instructions: LOAD x (copy x into the accumulator), ADD x, SUB x, MUL x and STORE x (copy the accumulator into memory x).
Compile y = (a + b) × c − d:
LOAD a
ADD b, so the accumulator holds a + b
MUL c, so it holds (a + b) × c
SUB d
STORE y
Now compile x = a × b + c × d. The two products must both exist before you add, but there is only one accumulator, so you need a temporary memory cell t:
LOAD a
MUL b
STORE t, saving a × b
LOAD c
MUL d
ADD t
STORE x
A compiler does exactly this kind of bookkeeping automatically: it respects the order of operations, invents temporary storage, and picks the right routine for each step.
Common mistakes:
Ignoring precedence. Compiling a × b + c × d left to right as ((a × b) + c) × d gives the wrong answer.
Overwriting a value you still need. Storing into a or b before you have used them breaks later steps.
Forgetting the final STORE. Without it the answer stays in the accumulator and is lost.
What did she do later?
MacTutor records that she retired from the Navy in August 1986 as a Rear Admiral and the oldest active-duty officer in the United States, and received the National Medal of Technology in 1991. In 2017 Yale renamed one of its residential colleges in her honour.
What can a student take from how Hopper worked?
Make tools for other people. Her compiler mattered because it let others program without learning machine code.
Keep going when told something is impossible. MacTutor reports that she had a working compiler that others were at first unwilling to use.
Get the story right. Even the famous moth is better told accurately.
For the theory that made all of this possible, read our profile of Alan Turing's computing machine, and for another early programmer, our profile of Dorothy Vaughan. If you want to strengthen the logic behind programming, the Fermi Concept Library covers every concept in mathematics and computing with its own explanation.
Try this now: compile z = (a − b) × (c + d) for the same machine, using as few instructions as you can.



