14 Weeks · 5 hrs/week Google Colab Python 3 · Functions → Data → Tests Core: Functional Decomposition Syllabus
"I can decompose a problem into small, testable functions"
Week 01 · 5 hours total

CP1 Review &
Refactor Thinking

You already know how to make code work. This week you'll learn to make it clean. We revisit CP1 essentials at speed, then introduce refactoring — the skill of improving code that already runs. The CONFIG cell pattern you'll use all semester starts here.

W01
Active Week
Phase 1 · Clean Code — Refactoring is the first step toward decomposition.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Learning Objectives
🔁Quickly recall CP1 core patterns: loops, functions, lists, file I/O
✂️Identify and apply four refactor moves: rename, extract, simplify, document
⚙️Set up a CONFIG cell at the top of every notebook with tunable parameters
📐Apply a refactor checklist to any CP1-era code snippet
🧹Write clear variable names, remove magic numbers, add one-line comments
🔍Recognize the difference between "working code" and "readable code"
This Week's Notebooks
📘 Weekly Notebook
Week_01.ipynb
CP1 Review & The Refactoring Mindset
⏱ ~5 hours · concepts + practice + exercises
  • CP1 review: variables, types, loops, functions, lists
  • What is refactoring? The four moves: rename, extract, simplify, document
  • Code smell catalogue: magic numbers, poor names, long functions
  • The CONFIG cell pattern
  • 15 exercises with engineering contexts
▶ Open in Colab
Key Concepts: Quick Reference
The CONFIG Cell Pattern
# ── CONFIG ─────────────────────────────
# Edit these values to control the notebook
DATA_URL     = "https://raw.github.com/.../sensor.csv"
WINDOW_SIZE  = 5      # moving average window
THRESHOLD    = 50.0   # outlier cut-off value
OUTPUT_DIR   = "./outputs"
# ───────────────────────────────────────
Refactor: Before vs After
# BEFORE (magic numbers, no function)
r = []
for x in d:
    if x > 0 and x < 50:
        r.append(x)

# AFTER (named, extracted, configured)
def filter_valid(data, lo=0, hi=THRESHOLD):
    """Return values in (lo, hi) range."""
    return [v for v in data if lo < v < hi]
Exercises Overview
L1 — Recall L2 — Apply L3 — Extend
E1
L1  Smell Hunt
Given 5 short code snippets, identify which "code smell" each contains: magic number, poor name, no comment, too long, no function.
E2
L2  Rename & Extract
Take the provided "working but ugly" temperature log script. Rename all single-letter variables and extract 2 logic blocks into named functions.
E3
L2  Add CONFIG Cell
Add a CONFIG cell to your refactored script with at least 3 tunable parameters. Confirm output is identical to the original using assert.
E4
L3  Full Refactor Sprint
Given a 40-line CP1-style sensor script with 7 identified smells, apply all four refactor moves. Before and after must produce identical output on the test dataset.