The night crew at mission control finds a strange Beacon reading while the team is asleep.
In the morning, Comet finds their note. "We could not tell what the average procedure was supposed to do. We left it alone."
Comet groans. "It was all in my head."
Wren nods slowly. "Then nobody else could fix it. Next time, we leave a trail."
Nova projects Comet's procedure with blank lines between the steps. "Interesting," she says. "There is room here for words."
"Comments," Wren says. "And a troubleshooting guide the night crew can follow without us."
Program documentation is a written description of what a code segment, event, procedure or program does, and how it was developed.
Comments are documentation written inside the program for people to read. They do not affect how the program runs.
Programmers should document a program throughout its development, not only at the end.
In Beacon's pseudocode, the crew starts each comment with two slashes. That is the crew's own choice.
// average: returns the mean of a list of readings.
// Assumes the list has at least one reading.
// Fixed in week 8: total now adds each reading.
PROCEDURE average(readings)
{
total ← 0
count ← 0
FOR EACH reading IN readings
{
total ← total + reading
count ← count + 1
}
RETURN(total / count)
} | Statement | True or false? |
|---|---|
| Comments change what a program does when it runs. | ? |
| Comments are written for people to read. | ? |
| Documentation should wait until the program is finished. | ? |
| Documentation can describe how a procedure was developed, not just what it does. | ? |
Effective ways to find and correct errors include test cases, hand tracing, visualizations, debuggers, and adding extra output statements.
This week you used three of them on paper: test cases, hand tracing and an extra DISPLAY line.
Troubleshooting also relies on experience: noticing that a problem is like one you have seen before, or reusing a fix that worked.
A guide such as a flow chart passes that experience on, so others can find and fix errors step by step.
Here is the start of Beacon's guide for the night crew.
Great documenting. Tomorrow you will test Beacon with the people who use it.