Patterns Save Effort Imagine your teacher asks you to write the word "Monday" in your school planner for every Monday for the entire year. There are 52 Mondays in a year. You would have to write "Monday" 52 times. Now imagine instead, you just write "Monday" once in your planner and put a small note: "repeat this every week." Same result. 1 write instead of 52. That is what patterns do for programmers. The Core Idea When something repeats — when the same instructions would need to be written again and again — a pattern lets you write them once and describe the repetition. Without patterns: write every individual step. With patterns: write the repeating unit once, then describe how many times it repeats. The bigger the repetition, the bigger the saving. Task Without Patterns With Patterns --- --- --- Print the word "Hello" 100 times Write the print command 100 times Write it once, repeat 100 times Move a character left and right (patrol forever) Write left, right, left, right... forever Write left+right once, loop forever Check 1,000 student test scores Write "check score" 1,000 times Write it once, apply to all 1,000 Send a birthday message to 500 contacts Write the send command 500 times Write it once, send to each contact The Connection to Loops You might remember loops from the very first series, Programming for Kids: How Computers Think. A loop was defined as: do something again and again, stop when the rule says so. Loops and patterns are deeply connected. A pattern is what you recognise: "this set of steps repeats." A loop is how you write it: "do these steps, and keep doing them until..." First you spot the pattern. Then you write a loop to express it. Without being able to spot the pattern, you would not know what to put inside the loop. Without the loop, you would have no way to express the "keep repeating" part. Spotting patterns is the thinking. Writing loops is the programming. Patterns Save Memory, Time, and Mistakes Writing less is not just about being lazy. Shorter, pattern-based programs are better in three important ways: 1. Fewer mistakes Every time you write a step, there is a chance of a small error. If you write the same step 100 times, there are 100 chances to make a mistake. Write it once and repeat — only one chance of a mistake, and the rest follow perfectly. 2. Easier to fix If you discover a mistake in a step that appears 100 times, and you wrote it out manually, you need to fix it in 100 places. With a pattern, you fix it in one place and all 100 repetitions are fixed automatically. 3. Easier to read A program that says "repeat this 100 times" is far easier to read and understand than one that says the same thing 100 times in a row. Did you know? Programmers have a short name for this rule: DRY , which stands for "Don't Repeat Yourself". It comes from a well-known book called The Pragmatic Programmer , and it is one of the most quoted pieces of advice in the whole job. The Song Chorus Think about a song with a chorus. The chorus might appear four times in the song. A songwriter does not write the chorus lyrics four times in the sheet music. They write them once, label them "CHORUS," and write "CHORUS" four times in the song structure where the chorus should appear. That is a pattern. The repeating unit (the chorus) is written once. The "CHORUS" label is placed wherever it should repeat. Programmers do exactly the same thing. They identify repeating units, write them once, and use them wherever they are needed. When There Is No Pattern It is worth noting: not everything has a pattern. Sometimes each step is genuinely unique. If you are writing a program that does 10 completely different things in a specific order — there is no pattern to spot. Each step must be written individually. The skill is in knowing the difference: If the steps are the same (or nearly the same) → pattern → write once, repeat If the steps are all genuinely different → no pattern → write each one Trying to force a pattern where there is not one makes a program harder to understand, not easier. Good programmers know when to use patterns and when not to. 🎯 Try This Yourself The Invitation Race You need one other person, plenty of paper and two pens. You are both inviting twelve friends to the same party. 1. Agree on the wording first — the name of the party, the date, the time, the place. Twelve invitations each, exactly the same words. 2. Player A writes all twelve out in full, by hand, every single word, every single time. 3. Player B writes the invitation once , leaving a blank space where the name goes, then writes just the twelve names on a separate list beside it. 4. Time yourselves. Then swap papers and hunt for mistakes in each other's work. 5. Now the twist: the party has moved from 4 o'clock to 5 o'clock. Change it. Count how many places each of you had to fix. What to watch for: Player A had twelve chances to make a mistake and twelve places to fix. Player B had one of each. That is the real reason…