Sub topic 2
How programming skill develops: practice, struggle and retrieval
The previous chapter argued that working code is not the same as learning. This chapter explains why. It describes what happens in your head when programming skill grows, and which kinds of practice make it grow.
This chapter assumes you can write functions, conditionals and loops in at least one language. It also assumes you can run a script in a terminal or editor, and that you have used a chat-based AI assistant or code completion at least a few times. No psychology background is needed.
What a programming skill is made of
Programming skill is not one thing. At least four parts develop at different speeds:
- Syntax and API knowledge. You know how to write a
forloop or callsorted()without looking it up. - Mental models. You can picture what the program does as it runs: where values live, how control moves, what a function call returns.
- Patterns. You recognize common shapes of problems, such as "count items by key" or "find the largest value that meets a condition", and you know the usual solutions.
- Process. You know how to break a problem down, test a guess, read an error message and recover when you are stuck.
An AI assistant can produce the visible output of all four. It writes the syntax, applies a pattern and even explains the model. But you only own a skill if you can use it later, without the assistant. That ownership has a technical name: the skill is stored in long-term memory and you can retrieve it when needed.
Why seeing a solution is weaker than producing one
Reading a correct solution feels like understanding. The code makes sense line by line, and you nod along. Psychologists call this the illusion of fluency: material that is easy to read feels like material you have learned.
The test is whether you could have produced it. Following a solution only requires recognition. Writing one requires you to recall the right ideas, choose between them and assemble them. Recognition is much easier than recall, so the two can come far apart.
A common example is a learner who reads a generated merge_sort and agrees with every line. A week later, with a blank editor, they cannot say where to begin. They did not fail to learn because the code was unclear. They failed because they never practiced the step that the blank editor demands.
Practice that builds skill
Three well-studied techniques apply directly to programming. Each makes the work harder in the moment and more durable later.
Retrieval practice
Retrieval practice means pulling information out of memory instead of looking at it again. Each successful or even partly successful recall strengthens the memory more than a re-read would.
In programming, retrieval looks like this:
- Writing a function from a one-line description with no reference open.
- Closing the tab with yesterday's solution and rewriting it.
- Answering "what does
defaultdictdo and when would I use it?" in writing before checking the docs.
Failed attempts still help, provided you check the answer afterward. The check matters. A wrong recall that you never correct can reinforce the mistake.
Prediction
Prediction means committing to an answer about what code will do before you run it. When the output differs from your guess, you have found a gap in your mental model at the exact moment it is cheapest to fix.
Try it. Write down your answer before running this code.
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"))The expected result is 6. The vowels are e, a, i in "Learning", i in "with", and a, i in "AI". If you got a different number, go back and find out why. Did you forget that .lower() makes the capital letters in "AI" count? Did you miscount? Did you misread the generator expression? Each of these is a different gap and needs a different fix.
A short habit is enough: write the prediction in a comment, run the code, and note whether you were right.
Self-explanation
Self-explanation means saying, in your own words, why each step works. "This line sorts the list" is a description. "I sort first so the middle element is the median, and I need an extra case for an even length" is an explanation, because it gives a reason.
If you cannot explain a line, you have found something to study. A later chapter turns this into a full practice of explaining code back. For now, treat the inability to explain as a signal and not as a failure.
Productive struggle
Learning research uses the phrase desirable difficulties for conditions that slow you down now and improve long-term retention. Struggling with a problem is one of them. The difficulty has to be the right size to work.
| Level of difficulty | What it feels like | Effect on learning |
|---|---|---|
| Too easy | Everything is obvious, you copy and paste | Little new memory forms |
| Productive | You are unsure, you try ideas, some fail, progress is slow but real | Strong learning |
| Too hard | You have no idea where to start and no way to find out | Frustration, little learning |
The middle row is the target. Two practical consequences follow.
First, being stuck is not a sign that something is wrong, as long as you are making attempts. A good rule is to spend a fixed time, such as 15 to 20 minutes, trying things and writing down what you tried. Only after that should you ask for help.
Second, the "too hard" zone is a real risk, so asking for help is not cheating. The aim is to ask in a form that keeps you in the productive zone. A hint or a question usually does. A full solution usually drops you into the "too easy" row.
Where AI changes the balance
Before AI assistants, the cost of getting a full solution was high. You had to search, read forum threads and adapt answers, and that effort kept some learning in the loop. Now a full solution costs one sentence. The pull toward the "too easy" row is stronger than it has ever been, and it works on every task, including ones you meant to learn from.
This is why the rest of this tutorial uses deliberate workflows. Willpower alone rarely holds against a free, instant answer.
Spacing and interleaving
Two more techniques matter once you have the basics.
Spacing means revisiting a skill after a gap of days instead of repeating it in one sitting. Rewriting a function from memory one day, three days and a week after you first learned it is far more effective than doing it three times in a row. The gap makes recall harder, and the harder recall builds the memory.
Interleaving means mixing problem types in a session, for example one string problem, one dictionary problem and one recursion problem, instead of ten of the same kind. Mixed practice forces you to decide which approach fits, and that decision is a real part of programming. Blocked practice hides it, because you already know which technique the next problem needs.
The learning loop
The techniques fit together into a loop. Each pass through it adds a little more to what you can do without help.
The loop has no step called "get the answer". Outside help can enter at the compare step, as a hint or a check, but the attempt and the recall remain yours.
A worked example: one function, three levels of practice
Suppose you are learning to compute the median of a list. Compare three ways to spend 20 minutes.
- Copy. Ask an AI for a
medianfunction, read it, agree with it and move on. Result: you can recognize a median function. Retention a week later is low. - Attempt, then compare. Write your own version first, run it on
[3, 1, 2],[4, 1, 3, 2]and[], and see which cases fail. Then compare your code to a reference and write down what you missed, such as the even-length case. Result: you know the specific mistakes you tend to make. - Attempt, compare, then retrieve. Do the second approach, and two days later, close everything and write
medianagain from memory. Result: the function and the reasoning behind it start to stick.
The third approach takes about the same total time as repeatedly asking an AI to solve variations. It trades a faster first pass for a lasting result.
Common mistakes
- Mistaking recognition for recall. "I read it and it made sense" is not evidence you can write it. Test yourself with a blank file.
- Skipping the check after a retrieval attempt. Recalling something wrong and never correcting it can lock the error in. Always compare against a trusted source afterward.
- Struggling without a limit. Open-ended struggle turns into frustration. Set a time box and a plan for what you will do when it ends.
- Predicting after running. If you look at the output first, you will convince yourself you would have guessed it. Write the prediction down before you run anything.
- Practicing only one problem type at a time. Blocked practice feels smooth and produces overconfidence. Mix in problems that need different techniques.
Summary of the working model
Programming skill grows when you retrieve, predict and explain, not when you read finished code. The effort is the mechanism and not a side effect of learning. An AI assistant can remove that effort so completely that no learning occurs, or it can be used to keep the effort at a productive level. The next chapters show how to choose roles for the AI and structure your work to get the second outcome.
Exercise
You read an AI-written function line by line and every line makes sense. Name two things you could do in the next 10 minutes to test whether you have learned it, and say which technique from this chapter each one uses.
Show answer
One option is to close the code and write the function again from a one-line description, which is retrieval practice. Another is to write down what the function returns for three specific inputs before running it, which is prediction. Explaining aloud or in writing why each line is there is a third valid choice, which is self-explanation. After any of these, compare your result against the original and note the differences.
Exercise
A learner solves ten string-reversal problems in a row and feels confident. Which two ideas from this chapter suggest their confidence may be misleading, and what change would you recommend?
Show answer
Blocked practice of one problem type hides the decision of which technique to use, and doing everything in one sitting skips spacing, so the practice feels easier than it is. Recommend mixing in problems of other types (interleaving) and repeating a few of them from memory on later days (spacing).
Exercise
You want to predict the output of count_vowels("Programming is fun"). Write your prediction, then explain what mistake would give 5 instead.
Show answer
The vowels are o, a, i in "Programming", i in "is", and u in "fun", so the result is 6. A result of 5 would come from missing one of the vowels, for example overlooking the "a" in "Programming" or the "i" in "is", which shows a counting slip and not a gap in the code logic.