Reading a Program Someone Else Wrote
Most code a person meets was written by somebody else. Working out what an unfamiliar program does, and then changing it on purpose, is a different skill from writing one from a blank screen.
What a learner can do afterwards
- Say in one sentence what an unfamiliar short program does, before running it
- Point at the part that would have to change to alter one named behaviour
- Make that change without breaking the rest, and say what was checked afterwards
1 · Read
Most code you meet was written by somebody else. Reading it differs from writing it. Your first job with a strange program is to say in one sentence what it does, before you run it.
Read this line: if 9 > 2 then 4 else 6. The test 9 > 2 is true, so the program picks the value after then: 4. Next: if 5 = 8 then on else off. The test 5 = 8 is false, so it picks the else answer, off. Branch values set the answer's kind, and = works on words too.
To change one behaviour, point at the part that controls it. In the line if score >= 50 then pass else retry, the test score >= 50 reads as score is 50 or more, and the pass mark lives inside it. Raising the mark to 60 means changing that number and nothing else.
After any change, check the rest still works. Rerun an old case that should stay the same, plus the new case you wanted. If 4 degrees now reads icy while 11 still reads ok, your one change landed cleanly.
Predict from reading, change the one part in charge, and recheck old plus new cases.
Practice items adapted from WeBWorK Open Problem Library problems by Jason Terry (Louisiana Tech) (CC BY-NC-SA 3.0). The reading prose was written for this dataset. The Fortran code example is retained from wikiHow's How to Program in Fortran: A Basic Guide; its license was not recorded.
2 · Watch
En anglaisTake it off screen
Where it sits
Where this leads
Jobs that lean on this skill. Follow one to see everything it is built on.
14 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.