Saturday morning, Comet arrives with a stack of blank index cards. "Let us make a matching game," she says.
Wren writes the lines of describe() on the cards, Python in pencil and Java in pen. "What does the evidence say?" he asks. "Every Python line should have a Java partner, or a reason it has none."
Nova projects the two methods, then fades them out so only the cards are left. "How can I help?" she asks. "Read each card aloud. Listen for the semicolons and the braces."
Comet shuffles the cards and hands them to you. "Lead programmer, play it with your family."
Here are the two files the cards come from: your sample.py, then Nova's Sample.java.
# sample.py
# A Sample is one rock or soil token the rover picks up.
class Sample:
"""One sample token from the test field."""
def __init__(self, label, kind, grams, row=0, col=0):
self.label = label
self.kind = kind
self.grams = grams
self.row = row
self.col = col
def describe(self):
return f"{self.label} {self.kind} {self.grams} g at ({self.row}, {self.col})"
def is_heavy(self):
return self.grams >= 50 // Sample.java
// The same Sample class as sample.py, written in Java.
public class Sample {
private String label;
private String kind;
private int grams;
public Sample(String label, String kind, int grams) {
this.label = label;
this.kind = kind;
this.grams = grams;
}
public String getLabel() {
return label;
}
public int getGrams() {
return grams;
}
public boolean isHeavy() {
return grams >= 50;
}
public String describe() {
return label + " " + kind + " " + grams + " g";
}
} Great matching, lead programmer. Next week the crew reads lists and algorithms in Java, and ships FieldSim.