Read Code Fast
Lesson 3 Skip on purpose
what to ignore (boilerplate, imports, getters) and what never to skip
What you'll learn
- Skip boilerplate on purpose: imports, constants, plain getters and logs
- Name the lines you never skip: conditions, deletes, error handling, money and input
- Spot the boring-looking line that is not boring
You can't read every line, and you shouldn't. Good reviewers skip a lot on purpose, and they know the short list of lines they never skip.
The idea
Skip what is boilerplate: imports of well-known modules, constants, type declarations, plain getters, logging, and glue that only passes things along. These lines are predictable, and a mistake in them is usually loud or harmless.
Never skip conditions, anything that changes or deletes data, error handling (catch, except), money, permissions and user input. And never skip a line that looks like boilerplate but isn't: a getter that changes something, a log line that prints a password. Skipping is a decision, not laziness: you glance, confirm the line is as dull as it looks, and move on.
1TAX_RATE = 0.2234class Cart:5 def __init__(self):6 self.items = []78 @property9 def count(self):10 return len(self.items)1112 @property13 def oldest(self):14 return self.items.pop(0)1516 @property17 def total(self):18 subtotal = sum(i["price"] * i["qty"] for i in self.items)19 return subtotal * (1 + TAX_RATE)
- Line 1 Skip: a constant. One glance (is the number sensible?) and move on.
- Line 9 Skip: a plain getter. It returns one thing and changes nothing.
- Line 14 Stop. This looks like a getter (
@property), butpop(0)removes the first item. Readingcart.oldesttwice gives two different items. - Line 18 Don't skip: this is money. Read the arithmetic.
Take away
- Skip the predictable: imports, constants, plain getters, logging, glue.
- Never skip conditions, deletes, error handling, money, permissions or input.
- Glance at what you skip: a boring line that does something clever is the one to stop on.
Quiz: test yourself
7 questions: a quick quiz, then a review drill. Pick an answer to see why it's right.