Module 02: Programming Model
Understand the small set of programming ideas that power most production code.
The Mental Model
Section titled “The Mental Model”Programs transform input into output, sometimes changing the outside world.
input -> parse -> validate -> decide -> transform -> store/respondMost programming is combining:
- Values.
- Data shapes.
- Functions.
- Control flow.
- Modules.
- Errors.
- Side effects.
Analogy
Section titled “Analogy”A program is like a kitchen recipe.
- Ingredients are input data.
- The recipe steps are control flow.
- Tools are functions.
- The kitchen layout is module structure.
- Food safety rules are validation.
- Burnt food is an error.
- Serving the dish is a side effect.
Concepts You Must Own
Section titled “Concepts You Must Own”| Concept | Plain Meaning | Example |
|---|---|---|
| Variable | Name for a value | title = "Login broken" |
| Type | What kind of value is allowed | string, number, boolean |
| Function | Reusable behavior | createTicket(input) |
| Conditional | Choose a path | if title is empty |
| Loop | Repeat work | send reminders for tickets |
| List | Ordered values | comments on a ticket |
| Map/object | Named fields | ticket record |
| Module | File/group of related code | ticketService |
| Error | Expected or unexpected failure | invalid input |
| Side effect | Change outside the function | database write |
Visual: Feature Logic
Section titled “Visual: Feature Logic”raw request -> parse JSON -> validate required fields -> check user permission -> create domain object -> save to database -> return responseWhat Separates Beginner Code From Useful Code
Section titled “What Separates Beginner Code From Useful Code”Beginner code:
- Mixes input parsing, rules, storage, and output in one place.
- Trusts input.
- Ignores errors.
- Has no tests.
- Works only for the happy path.
Useful code:
- Separates responsibilities.
- Validates boundaries.
- Names concepts clearly.
- Handles expected failures.
- Has tests for important behavior.
Build Drill
Section titled “Build Drill”Build a CLI task tracker:
task add "Call customer"task listtask done 1Separate it into:
- CLI parsing.
- Task logic.
- Storage.
- Display formatting.
Required Tests
Section titled “Required Tests”- Adding a task creates an open task.
- Marking a task done changes only that task.
- Empty title is rejected.
- Unknown task ID returns a clear error.
- Corrupted storage file is handled intentionally.
Agentic Angle
Section titled “Agentic Angle”Ask an agent:
Review this task tracker for mixed responsibilities, missing validation,untested behavior, and unclear names. Suggest improvements without rewritingthe whole program.Questions
Section titled “Questions”- Which functions are pure?
- Which functions have side effects?
- Where is input validated?
- Where are errors converted into user messages?
- What data shape represents a task?
- What behavior should be tested first?
- Create the task tracker.
- Write a data shape for tasks.
- Write task logic without file I/O first.
- Add tests for logic.
- Add file storage.
- Add CLI parsing.
- Break the storage file and handle the error.
- Write
programming-model.mdexplaining the flow.
Done When
Section titled “Done When”- You can run the CLI from a terminal.
- Tests pass.
- Bad input gives a useful error.
- You can explain pure logic versus side effects.