Week 17 · 17.2 · Tue, Dec 1 · I Do: ACT-style reading
Choosing What to Do: From Apollo 11 to Java's if
1 This section explains how the computer that helped land Apollo 11 chose what to do when it had too much to do, and how a Java program runs some lines only when a question has the answer true.
Too Much to Do
2 In July 1969, Neil Armstrong and Edwin Aldrin flew the lunar module Eagle down toward the surface of the Moon. Michael Collins, who stayed in orbit above them, later described what happened about five minutes into the landing burn. Armstrong reported a program alarm, a 1202. Collins's checklist said that a 1202 was an executive overflow, meaning that the computer had been called upon to do too many things at once. At about three thousand feet above the surface, the computer flashed a 1201, another overflow, and again the ground answered quickly that the landing was go.
3 Don Eyles, one of the programmers who wrote the lunar module's guidance software, later explained the alarms in a paper. The alarm was issued when the computer was overloaded, when it had more work to do than it had time for. A radar that was not needed for the landing was asking the computer for attention, and its counters used up roughly 15 percent of the available computation time.
How the Program Chose
4 The program that ran the computer's jobs, called the Executive, always ran the job with the highest priority. Each new job needed a small area of memory to run in, and Eyles describes what the Executive did when none was left. If no "core sets" were available, the Executive called a routine named BAILOUT with alarm code 1202. If no "VAC areas" were available, it called BAILOUT with alarm code 1201. The restart that followed kept the most recent run of the guidance job and dropped the unfinished leftovers. On the ground, a 26-year-old guidance officer named Steve Bales had to say go or abort, and he said go.
5 Each of those choices rests on a question with a true or false answer. Is an area of memory available? If the answer is no, raise the alarm. The program did not simply run every line it had. It checked a condition first and then chose what to do.
A Program Decides
6 Java makes the same kind of choice with an if statement. Oracle's Java tutorial says that an if statement tells a program to run a certain section of code only if a particular test evaluates to true. The test is the condition: the true-or-false question in the parentheses after the word if. The lines inside the braces below the if line are its block. If the condition is false, the tutorial says, control jumps to the end of the if statement, so the block is skipped.
1int score = 82; 2if (score >= 70) 3{ 4 System.out.println("pass"); 5} 6System.out.println("done");
7 When score is 82, the condition score >= 70 is true, so lines 1, 2, 4 and 6 run, and the program prints pass and then done. When score is 55, the condition is false, so only lines 1, 2 and 6 run, and the program prints only done. The if line itself always runs, because it is where the program decides. Figure 1 shows both paths.
8 Two mistakes are easy to make, and the compiler catches neither one. A semicolon right after the parentheses ends the if statement, so the block below it runs every time. The braces can also be left out when the block has only one statement, but the tutorial warns that this makes code brittle: a second statement added later runs every time, and the program gives the wrong results.
9 Today's question asks how a Java program could run some lines only when something is true and skip them when it is false. The word if starts the check, the condition in the parentheses asks the true-or-false question, and the block in the braces runs only when the answer is true. On today's bench, each program is followed one line at a time to see which lines run.
Summary
10 In July 1969, the guidance computer on Apollo 11 had more work to do than time to do it. Its Executive program checked a condition, whether an area of memory was available, and when none was, it raised the 1202 or 1201 alarm and restarted, keeping the guidance job that mattered most. A Java if statement makes the same kind of choice. Its condition is a true-or-false question, and its block runs only when the answer is true.
Sources: Don Eyles, Tales from the Lunar Module Guidance Computer (2004); NASA SP-350, Apollo Expeditions to the Moon, chapter 11.4; NASA, Apollo 11 mission page; Oracle, The Java Tutorials: The if-then and if-then-else Statements; course repository, snippets run with the course JDK.
Read the passage on the left. Answer each question by clicking a choice: the right answer turns green, and a wrong one tells you why. Questions point to paragraph numbers, as on the ACT.
1. Main idea
The main purpose of the passage is to:
2. Detail
According to paragraph 2, Collins's checklist said that a 1202 alarm meant that the computer:
3. Detail
According to paragraph 3, what used up roughly 15 percent of the computer's available time?
4. Detail
According to paragraph 4, what did the Executive do when no "core sets" were available?
5. Function
The main function of paragraph 5 is to:
6. Vocabulary
As it is used in paragraph 6, the word condition most nearly means:
7. Detail
According to paragraph 7, which lines of the score program run when score is 55?
8. Detail
According to paragraph 8, what happens when a semicolon is placed right after the parentheses of an if?
9. Synthesis
Based on the passage as a whole, the Apollo 11 Executive and a Java if statement are alike because both: