{module 1}
The six-step method
Orientation15 min read
What you will be able to do
- Name the six steps of the method in order.
- Use the six steps to solve a small business problem by hand.
- Explain why planning before you type saves time.
Why it matters
Cedar Bakery is a bakery in Beirut, Lebanon. On a busy Saturday a customer asked for three loaves and two cakes, delivered. A new assistant worked out the price on a calculator and wrote $60.00 on the order. The right price was $54.50. The customer knew the bakery's offer, noticed the difference, and complained. The bakery lost a regular.
The assistant knew how to add and multiply. What went wrong was not arithmetic. The order had earned a discount, and he never applied it. Nobody had asked him to say the rule back before he started.
Most mistakes in software are like this one. The typing is correct. The thinking before the typing was skipped. This lesson gives you a method for the thinking. You will use it in every lesson of this course and on every project.
The idea
When a problem is new, the natural thing is to start at once. You type something, see what happens, and change it until it looks right. This works for very small problems. For anything larger it is slow, because you do not know what "right" is, and you cannot tell which change helped.
The six-step method replaces that with an order of work.
1. Understand
Say the problem in your own words. What goes in? What must come out? What must be true at the end? If you cannot say it plainly, you do not understand it yet, and no amount of typing will fix that. Ask questions now, when they are cheap.
2. Break down
Split the problem into smaller parts that can each be solved alone. A good part is small enough that you can see how to do it. If a part still feels too big, split it again.
3. Plan
Decide the order of the parts before you type. Write the plan as a short numbered list. A plan takes two minutes and shows you the gaps: the part you forgot, and the part that depends on another.
4. Build
Make the smallest piece that works, and check that it works. Then add the next piece. Never build everything and then look at it for the first time. When each step is small, a mistake has only one place to hide.
5. Test
Check the result against a case where you already know the answer. Then check one odd case: zero items, a very large order, an amount that sits exactly on a limit. The odd cases are where rules break.
6. Reflect
Stop and look back. What would you do differently? What did you learn that you can use again? This step takes one minute and is the one most people skip. It is also how the next problem becomes easier than this one.
The method is not only for code. It works for a price, a letter, a plan for a week or a page that does not look right. That is why this lesson has no code in it.
Worked example
Here is the bakery's rule, as the owner wrote it:
Loaves cost $5.00 and cakes cost $20.00. Orders of $50.00 or more, before delivery, get 10% off. Delivery is $5.00 and is never discounted.
The order: three loaves and two cakes, delivered. What should the customer pay?
Understand. What goes in: how many loaves, how many cakes, and whether the order is delivered. What comes out: one price. In my own words: "Add up the goods. If the goods come to $50.00 or more, take 10% off the goods. Then add delivery if there is any." One thing needs care. Does "$50.00 or more" include exactly $50.00? The words say yes.
Break down. Four parts:
- the price of the loaves
- the price of the cakes
- the discount, if the order has earned one
- the delivery fee
Plan.
- Work out the loaves.
- Work out the cakes.
- Add them. This is the goods total.
- If the goods total is $50.00 or more, take 10% off it.
- Add $5.00 if the order is delivered.
Build. One step at a time, checking each:
- Loaves: 3 × $5.00 = $15.00
- Cakes: 2 × $20.00 = $40.00
- Goods total: $15.00 + $40.00 = $55.00
- Is $55.00 at least $50.00? Yes. 10% of $55.00 is $5.50, and $55.00 − $5.50 = $49.50
- Delivery: $49.50 + $5.00 = $54.50
Test. First a case where the answer is known. One loaf, collected, costs $5.00, with no discount and no delivery. The plan gives $5.00. Now the odd cases, on both sides of the limit. One loaf and two cakes is $45.00 in goods, which is under $50.00, so there is no discount. Two loaves and two cakes is exactly $50.00. The rule says "or more", so this order gets 10% off and costs $45.00. The plan agrees with the rule each time.
Reflect. The price is $54.50. The assistant's $60.00 is the goods plus delivery with no discount, so he skipped step 4. A second mistake was waiting in the same rule. Taking 10% off the delivery fee as well would give $54.00. Saying the rule back at the start, "the discount is on the goods only", prevents both. Next time, the first thing I write down is the rule in my own words.
Common mistakes
Starting at step 4. You begin to build before you can say the problem. The sign is that you keep changing your answer and cannot explain why the last version is better.
Parts that are too big. "Work out the price" is not a part. It is the whole problem again. Keep splitting until each part is one calculation or one decision.
Testing only the easy case. One loaf, collected, will pass with almost any plan. The order of exactly $50.00 is the one that proves you read the rule correctly.
Skipping Reflect because the answer is right. A right answer teaches you nothing unless you ask how you got there. One sentence is enough.
Think it through
Zanzibar Spice Walks runs walking tours in Stone Town, Tanzania. A tour costs $12 for each adult and $6 for each child. A group of six or more people gets $10 off the total. A family of two adults and four children wants to book. What do they pay?
Understand. In: the number of adults and the number of children. Out: one price. The discount depends on the number of people, not on the price.
Break down. The adults' price, the children's price, the count of people, and the group discount.
Plan. Price the adults. Price the children. Add them. Count the people. If there are six or more, take off $10.
Build. Adults: 2 × $12 = $24. Children: 4 × $6 = $24. Total: $48. People: 2 + 4 = 6. Six is "six or more", so the price is $48 − $10 = $38.
Test. One adult alone pays $12, and the plan gives $12. A group of five gets no discount, and a group of exactly six does.
Reflect. The risk was counting only the adults as "people". Saying the rule in my own words at the start settled it.
At work
Before you start any piece of work for someone else, say the problem back to them in your own words. This is the Understand step, done aloud.
A developer who is asked to "add a discount to the order page" does not open the editor. She writes back:
To check I have understood: orders of $50 or more get 10% off the goods, delivery is never discounted, and exactly $50 counts. Is that right?
It takes one minute. Half the time the client answers "yes". The other half they answer "no, the discount is only on weekdays", and you have saved a day of building the wrong thing. Clients do not find this annoying. They read it as care, and it is the first reason they come back.
Your tasks
Task 1: Learn the six steps
Write the six steps on paper from memory, in order, with one short sentence after each that says what you do in that step.
You are done when you can write all six without looking, and each has its sentence.
Task 2: Price an order by hand
Use the bakery's rule from the worked example. Price this order with all six steps written out: five loaves and two cakes, collected by the customer.
You are done when you have a price, a test of one easy case and one odd case, and a sentence under Reflect.
Task 3: Find the gap in a rule
A gym writes: "Members pay $30 a month. Students get 20% off. Everyone who joins in January gets the first month free." A student joins in January and asks what they will pay in the first three months. Use the first two steps only, Understand and Break down, and write the one question you would have to ask the gym before you could plan.
You are done when you have written the question, and you can explain why the rule cannot be priced without the answer.
Recap
- The six steps are Understand, Break down, Plan, Build, Test and Reflect.
- If you cannot say the problem in your own words, you are not ready to build.
- Build the smallest piece that works, check it, then add the next piece.
- Test a case where you know the answer, and one odd case on a limit.
- Reflecting for one minute is what makes the next problem easier.
Go deeper
- Wikipedia: How to Solve It summarises the book by George Pólya that this kind of method comes from.
- MDN: Workflows and processes describes how professional developers plan and organise their work.
- MDN: Solve common JavaScript problems is a page to return to once you start writing JavaScript in module 4.