By the end of this lesson, cadets will be able to:
Complete before class. These set the vocabulary we will use.
| Source | Sections | Why |
|---|---|---|
| Lesson 23 supplementary notes | All sections | The four-step process you will use today |
| DFCS C Programming Standard | §2.2 (function header blocks), §8.5 (always free dynamically allocated memory) | Today\'s touchpoint: ownership documented at the header |
| Beej-C | Chapter 15 (Multifile Projects) revisit | Skim. Refresher on what goes in .h vs .c |
On every lab so far, the spec told you what functions to write. You implemented prototypes that someone else (your instructor) decided on. That work was important, but it skipped the question every real C developer asks first: how did you decide the program should look like THIS?
Today is the lesson where that question gets a process and a vocabulary. You have been doing the underlying skill all semester. At Lesson 6 you refactored a monolithic main into functions you named. At Lesson 19 you designed structs around the data they hold. At Lesson 20 you decided what belongs in a header. Each of those was decomposition in disguise. Lesson 23 is where it gets a name.
The lab is the rehearsal for your Team PEX design check-in. The widget walks you through a small example. The lab takes you through one yourself, with a written deliverable.
A repeatable way to go from a written requirements document to a sketch of the program:
The widget in Section 5 walks you through every step on a small flashcard-study example before you tackle the lab.
A header is a contract. Anything you put in it is a public promise to the rest of the codebase. The smaller and more honest the header, the easier the program is to maintain.
Put in the header:
typedef, enum, struct forward declarations.Keep OUT of the header:
static. It is internal by design.extern; this is rare).Any function that returns a pointer is making a statement about ownership. The header is where that statement gets written down. Three patterns cover most cases:
free it (or call a matching destructor). load_deck above is one. malloc, strdup, fopen are standard library examples.The doc comment on the header is where the pattern gets named. If a teammate has to guess, the header is wrong. This is exactly the DFCS §8.5 discipline: every malloc has a matching free, and the design says who calls each.
The third deliverable today is a short written memo, about one page, that captures your design choices in prose. The lab template gives you a structure to fill in. The required sections:
The testing section is not an afterthought. If you cannot name a test case for a function, your interface is underspecified: the function has no observable result, or the inputs are not well defined. Change the design before you write code.
Today touches two sections of the standard:
See the Resources section for the full standard text.
Twelve design decisions on a small flashcard-study spec. Read the spec in the right pane, then answer each prompt. The right pane records your decisions as you go.
Enter your name. It will appear on the completion screen so you can include it in your screenshot for the Lesson 23 reflection.
Eight questions on header design, module boundaries, and ownership. Pass at 70% or above; below that, take it again after reviewing.
Enter your name. It will appear on the score card so you can include it in your screenshot for the Lesson 23 reflection.