Story
Now Alice really uses her app, and using it teaches her what writing it did not. Some todos have to wait: she cannot ship the thing before the tests are written. So a todo keeps a list of the todos it waits for, and she says so when she writes it down. If she tries to finish a todo that is still waiting, the app says no, because a rule nobody checks is only a note.
Her eyes are the other problem. The list prints everything at once and the ones that matter hide in the middle, so now she can ask for less: the open ones, the finished ones, or all of them. And she can ask the question she asks most often and can never answer by looking: what am I allowed to start right now? She never writes that down. It is simply a todo that is not finished and waits for nothing, so the app works it out for her.
None of these are big changes on their own. But each one leaves a little more thinking in the same file, and when she
reads it she sees two different jobs sitting side by side: understanding what she typed in the terminal, and knowing
what a todo is. So she cuts the file in two. main.ts talks to the terminal, and todo.ts knows about todos. She only
moves the code and changes nothing, so the printing travels with it, and the help text travels too, because it lists
the commands and the commands live there now. When she is done, main.ts is a switch and nothing else, while todo.ts
knows her words, her flags and every line on her screen. It looks tidy. She cannot yet see that she drew the line in
the wrong place.
Alice's Notebook
- Give every command its own function instead of writing its body inside the switch block.
- Keep the code that reads the terminal apart from the code that knows what a todo is.
Choose a file from the tree.
;
;
switch command {
case "add":
rest;
break;
case "list":
rest;
break;
case "done":
rest;
break;
case "remove":
rest;
break;
default:
;
};
;
;
;
;
;
if !dir dir;