Boss lesson · Unit 02
Why is it like this?
Ask the history before you remove the fence
What you practise
- Blame and commit messages as evidence, the fence you should not remove before learning why it is there, reading a series of commits as an argument
Try a question from this lesson
Pick one
You are tidying this paging function. Page numbers start at 1, so its second line looks pointless. What do you do first?
def page(items, n, size):
n = max(n, 1)
lo = (n - 1) * size
return items[lo:lo + size]function page(items, n, size) {
n = Math.max(n, 1);
const lo = (n - 1) * size;
return items.slice(lo, lo + size);
}function page<T>(
items: T[],
n: number,
size: number,
): T[] {
n = Math.max(n, 1);
const lo = (n - 1) * size;
return items.slice(lo, lo + size);
}Correct answer
Find out why it was added
Why
A line that looks pointless was usually added for a reason you cannot see from where you stand. The history can tell you in a minute what production would otherwise teach you in a week.
TypeScript notepage<T> is generic: whatever the item type T is, a page of T[] comes back. Nothing in paging depends on what the items are.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
The fence
An old rule of thumb: you find a fence across a road, with no purpose you can see. Do not take it down until you know why it was put up.
In code the fence is the odd check, the strange default, the retry nobody remembers. Blame and the commit message are how you ask the person who built it.
10 more exercises in the app
- 2× type the answer
- 5× multiple choice
- 1× true or false
- 1× fill the blanks
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.