Sub topic 2
How Programming Skill Develops: Practice, Struggle and Retrieval
This chapter assumes you can write functions, conditionals and loops in Python, run a script in a terminal or editor, and have used a chat-based AI assistant. It explains how programming skill is built. The later chapters on workflows and prompting rely on this model.
Skill Is Built by Retrieval, Not Exposure
Reading a solution feels like learning. You follow each line, it makes sense, and you move on. Psychologists call the resulting confidence the illusion of fluency. Recognizing code is easier than producing it, so recognition tells you little about whether you could write the code yourself.
Three practices build skill that lasts:
- Retrieval practice means pulling an idea out of memory without looking at it. Writing a loop from scratch is retrieval. Rereading one is not.
- Prediction means stating what code will do before you run it. A wrong prediction shows you exactly where your mental model differs from the real behavior.
- Self-explanation means describing in your own words why each step works. If you can't explain a line, you don't yet understand it.
Desirable Difficulty
Effort that feels uncomfortable is often the effort that produces learning. Researchers call this a desirable difficulty. Struggling to recall a syntax detail, or staring at a wrong output, forces your memory to rebuild the idea. That rebuilding makes the idea easier to recall next time.
Not all struggle helps. Being stuck for an hour on a misspelled variable teaches you little. The useful zone is a problem you can nearly solve. Too easy, and nothing is built. Too hard, and you only get frustrated.
Why This Matters When an AI Is Available
An AI assistant can remove the struggle in one message. That is useful when the struggle is pointless, such as a confusing error message. It is harmful when the struggle was the learning. If the assistant produces the loop, the prediction and the recall never happen, and you skip the work that builds the skill. The task gets done, but your ability stays the same.
Worked Example: Predict, Then Run
Take this function. Before running it, write down what you expect the output to be.
def count_vowels(text):
return sum(1 for ch in text.lower() if ch in "aeiou")
# Predict the output before you run this line.
print(count_vowels("Learning with AI"))Count by hand: "Learning" has e, a, i (3). "with" has i (1). "AI" has a, i after lowercasing (2). The expected result is 6.
Now run it. If the output matches, your model of lower() and the generator expression is sound. If it does not, do not just fix your answer. Ask which part of your model was wrong. Did you forget that lower() turns "A" and "I" into vowels the check can match? Did you miscount letters? That investigation is the learning.
Spacing Your Practice
Retrieval works best when it is spaced. Solving the same kind of problem on day one, day three and day ten builds stronger memory than solving it five times in one evening. A practical routine:
- After you learn a concept, write a small example from memory the next day.
- Repeat a few days later, with a small variation.
- Return to it after a week, with no notes and no AI.
Each pass should feel slightly harder than rereading. That feeling signals that retrieval is happening.
| Activity | Feels like | Effect on skill |
|---|---|---|
| Rereading a solution | Easy, familiar | Low |
| Copying code from an AI | Fast, productive | Low |
| Predicting then running | Mildly uncomfortable | High |
| Writing from memory | Hard | High |
| Explaining code aloud | Awkward | High |
Common Errors
- Judging progress by finished tasks. Working code shows the task is done. It does not show you can repeat it alone.
- Giving up the struggle too early. If you ask for help within a minute, you lose the recall effort. Try for a set time first.
- Struggling too long. Past the point of useful effort, ask for a hint. A later chapter gives a workflow for this.
- Skipping the prediction. Running code first makes the result feel obvious in hindsight.
Exercise
You ask an AI for a function that reverses the words in a sentence, read it, and it makes sense. Which of the three practices from this chapter did you skip, and what could you do now to build the skill?
Show answer
You skipped retrieval and prediction. Recognizing the code is not the same as being able to write it. Hide the solution and write the function from memory. Before running it, predict the output for a sample sentence. Then explain each line in your own words, and try again from memory a few days later.