Junior, mid and senior answers
medium 45 minThe same prompt is given to people with two and with twelve years behind them.
Video lesson · Chapter 1 of 6
Make a prediction
See it run
The same two calls, sell and redeem. Each level answers one more question.
Operations
Junior: it works
Eleven drinks, one free drink, one stamp left. Then somebody else writes the field.
Step 1 of 5
Ten drinks later
The till called buy ten times.
Step 1: Ten drinks later
def buy(self): self.stamps += 1def redeem(self): if self.stamps >= 10: self.stamps -= 10 return True return False- Question
- does it work?
- Adds
- a counter
Trace with eleven, not ten.
In the real world
The same one stamp card, four levels doing real jobs. Pick one and step through it.
Sam used ten stamps, then gives back six drinks.
Step 1 of 4
Twelve stamps
Two sales of six.
Step 1: Twelve stamps
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Reset to zero
majorThe eleventh stamp is lost.
Wrongif self.stamps >= 10: self.stamps = 0Rightif self.stamps >= 10: self.stamps -= 10Check outside the lock
criticalTwo tills pass the check together.
Wrongif ledger.balance() >= goal: with ledger.lock: ledger.record(entry)Rightwith ledger.lock: if ledger.balance() >= goal: ledger.record(entry)A sale without a name
criticalA retry looks like a new sale.
Wrongshop.sell("sam", 1)Rightshop.sell("sam", receipt, 1)Reading the real date inside
majorThe test would have to wait.
Wrongday = date.today()Rightday = self._today() # handed inEditing history
majorAfterwards nobody can explain the balance.
Wrongentry.stamps = 0Rightledger.record(Entry("x", "refund", -6, day))
Interview tips
Before you start
- Ask which level.
- Core in 15 minutes.
- Say what you leave out.
To look senior
- Name two failures yourself.
- Put the check inside.
- Test the retry.
To look staff
- Cost of a mistake.
- Speed of change.
- The smaller design.
What lowers you
- Castles.
- Silence.
- Defending a mistake.