Comet stretches. "FieldSim shipped. Can we call it finished?"
Wren shakes his head and clips a fresh sheet to his clipboard. "What does the evidence say? A code review checks the qualities of a program, not just whether it runs."
Nova projects one more Java file first, the recursive countdown. "How can I help?" she asks. "Then I will show a checklist. You decide what it says about FieldSim."
Comet reads the Java countdown and grins. "That is our countdown, with braces."
Wren hands you the checklist. "Lead programmer, you are the reviewer today."
// CountdownDemo.java
// The recursive countdown from recursion.py, written in Java.
public class CountdownDemo {
public static void countdown(int n) {
if (n == 0) {
System.out.println("Go!");
} else {
System.out.println(n);
countdown(n - 1);
}
}
public static void main(String[] args) {
countdown(3);
}
} 3 2 1 Go!
# countdown_twin.py # The Python twin of CountdownDemo.java, using your recursion.py. from recursion import countdown countdown(3)
# countdown_twin.py
# The Python twin of CountdownDemo.java, using your recursion.py.
from recursion import countdown
countdown("3") 3
Traceback (most recent call last):
File "countdown_twin.py", line 5, in <module>
countdown("3")
~~~~~~~~~^^^^^
File "recursion.py", line 10, in countdown
countdown(n - 1)
~~^~~
TypeError: unsupported operand type(s) for -: 'str' and 'int' A code review checks qualities such as correctness, usability, readability, efficiency, portability and scalability.
Wren adds one fact to the review. This short program counts the letters in Pip's route:
# route_count.py
route = "FFRFFFLFFLFRRFFLF"
print(len(route), "commands")
print(route.count("F"), "steps forward") 17 commands 11 steps forward
| Quality | Question for fieldsim.py | Evidence to look at |
|---|---|---|
| Correctness | Does it give the right result? | The output and test_fieldsim.py |
| Readability | Can another programmer follow it? | Names, docstrings and comments |
| Efficiency | How much work does it do? | collect_here runs once per command |
| Usability | Is the output clear to a reader? | The grid, the status line and the list |
| Portability | Will it run on another computer? | It uses only Python and its own files |
| Scalability | Would it handle a bigger field or more rovers? | One Rover named Pip is built in main |
That was a careful review, lead programmer. Tomorrow you will write down the design so the next programmer can understand it.