Sub topic 1
Why Working Code Is Not the Same as Learning
An AI assistant can give you a correct function in seconds. That is useful, and it also creates a trap. You can finish a task, see the tests pass, and still be unable to write the same code tomorrow without help. This chapter explains why that gap exists and what the rest of the tutorial does about it.
Prerequisites
This chapter assumes you have:
- Basic programming in at least one language: variables, functions, conditionals and loops.
- The ability to run a script and a simple test in a terminal or editor.
- Some experience with a chat-based AI assistant or a code completion tool.
The examples use Python, but the ideas apply to any language.
Two different goals
When you work on a programming task, you can be after one of two outcomes.
- A product. You want working code: a script that runs, a feature that ships, a test that passes.
- A skill. You want to become someone who can produce that kind of code, and who can understand, change and debug it later.
Before AI assistants, the two goals were closely tied. The only way to get the product was to build the skill, at least partly. Struggling with the problem was the cost of the working code, and that struggle was also what taught you.
AI assistants separate the two. You can now get the product with very little skill. That is a real benefit for professionals who need output. For a learner it is a problem, because the product is not what you are trying to obtain. The exercise was only ever a vehicle for building the skill.
What goes wrong when you skip the work
Suppose you are learning Python and you are asked to count the vowels in a string. You paste the task into an AI assistant and receive this:
def count_vowels(text):
return sum(1 for ch in text.lower() if ch in "aeiou")
print(count_vowels("Learning with AI"))You run it, it prints a number, and you move on. Nothing here was wrong. The problem is what did not happen:
- You did not decide how to loop over the characters.
- You did not think about uppercase letters, and so did not discover why
lower()is there. - You did not try a wrong version and see why it failed.
- You did not read the generator expression closely enough to know what
sumreceives.
Each of these is a small piece of understanding. Skipping all of them on every task adds up to a large gap, and that gap stays hidden until you have to work without the assistant.
The illusion of competence
Reading a correct solution feels like understanding it. The code looks reasonable and each line seems to follow from the last. Psychologists call this the illusion of competence: the sense of knowing something that comes from recognizing it, not from being able to produce it.
Recognition and recall are different abilities. Recognition asks, "Does this look right?" Recall asks, "Can I write this from nothing?" Programming work requires recall. When you open an empty file, nothing is there to recognize.
You can test the difference on yourself with the vowel example. Before you run the code above, cover it up and write down what you expect it to print. Then write your own version of count_vowels without looking. If you can predict the output but cannot write the function, you have recognition without recall.
For the string "Learning with AI", count the vowels by hand: e, a, i, i, A, I. The expected result is 6. If the program prints something else, do not assume the program is wrong. Check your count first, then the code, and note which one you had mistaken.
Why the gap stays hidden
The gap between a finished task and a learned skill is easy to miss, for several reasons.
- Feedback looks positive. Tests pass, the program runs, and the assistant is confident. Nothing signals that you learned little.
- The cost is delayed. You pay later, when you face a new problem, an interview, a bug in code you do not understand, or a situation with no assistant available.
- Progress feels fast. You complete more tasks in less time. Speed of output is easy to confuse with speed of learning.
- Understanding is hard to measure from inside. You usually cannot tell what you do not know until you are asked to use it.
The result is a pattern many learners report: they finish a course or a set of projects with a long record of completed work and still feel unable to start a program on their own.
Where AI help is useful and where it is not
AI is not the problem. The problem is using it in a way that removes the effort that builds skill. The same assistant can either support learning or undermine it, depending on what you ask for and when.
| Use of AI | Effect on learning | Why |
|---|---|---|
| Asking for a full solution before trying | Usually harmful | Removes the struggle and the recall practice |
| Asking for a hint after a real attempt | Helpful | Keeps your reasoning and adds targeted feedback |
| Asking for an explanation of code you wrote | Helpful | Connects your attempt to correct concepts |
| Asking for a review after you fix the problem | Helpful | Shows improvements you could not see yourself |
| Copying generated code you cannot explain | Harmful | Gives you a product you cannot maintain |
| Asking for an alternative approach after you have a working one | Helpful | Widens your options once you have a baseline |
The pattern in the table is consistent. AI help works when it follows your own effort and harmful when it replaces that effort. Later chapters turn this into concrete workflows.
Checking the product, not only the producer
Working code is still worth checking, because AI output is not always correct. A tutorial on learning has to cover both problems: you might not learn, and the code you did not learn from might be wrong.
Consider this function, of the kind an AI might produce:
def median(values):
if not values:
raise ValueError("median() requires at least one value")
ordered = sorted(values)
mid = len(ordered) // 2
if len(ordered) % 2 == 1:
return ordered[mid]
return (ordered[mid - 1] + ordered[mid]) / 2
assert median([3, 1, 2]) == 2
assert median([4, 1, 3, 2]) == 2.5
assert median([5]) == 5
try:
median([])
except ValueError:
pass
else:
raise AssertionError("median([]) should raise ValueError")This version is correct. The four checks cover an odd number of items, an even number, a single item and empty input. Notice who wrote those checks. If you only accept the function, you depend on the assistant's judgment. If you write the checks yourself, you must understand what the function should do, and that understanding is the skill you are trying to build.
If you ask the assistant to write the tests as well, you lose this benefit. The same model that made a mistake in the code can make a matching mistake in the tests, and both will pass. Tests you write from your own understanding of the problem are an independent check.
Struggle that helps and struggle that does not
The argument so far could be misread as "make everything hard." That is not the claim. Some difficulty builds skill and some only wastes time.
- Productive struggle is effort on the core of the problem: choosing a loop, tracing a value, working out why an index is off by one. It feels slow, and it is what you remember.
- Unproductive struggle is effort that teaches nothing: a missing colon you cannot see, an environment that will not install, a cryptic error from a tool you have not met.
AI is well suited to removing the second kind. Asking an assistant to explain an installation error is a good use. Asking it to design your algorithm is usually not. The skill you are building decides which category a given difficulty falls into. For a beginner, a syntax error may be productive once or twice. For an experienced learner, it is noise.
A practical rule is to ask yourself: "If the assistant removed this difficulty, would I lose the thing I came here to learn?" If yes, do it yourself first. If no, let the assistant help.
What the rest of this tutorial covers
The remaining chapters build a working method in stages.
- How programming skill develops, including practice, struggle and retrieval.
- The roles an AI can take: tutor, reviewer or generator.
- An attempt-first workflow, and prompts that ask for hints and explanations.
- The ways AI answers go wrong, and how to read and test generated code.
- Debugging with AI while keeping your own reasoning, and explaining code back in your own words.
- Projects with clear AI boundaries, reducing support over time, and tracking progress with unaided checks.
As a preview, here is the kind of prompt the tutor role uses. It asks for a question and a hint, and it keeps the solving with you.
I am learning Python. I tried to write a function that returns the median of a list, and my code is below.
<paste your code and the error or wrong output>
Do not give me the full solution. First, ask me one question that helps me find the problem. If I am still stuck, give a hint. After I fix it, review my code and tell me what to improve.You will see how to build and adjust prompts like this one in later chapters. For now, notice what it does: it states your level, shows your own attempt, and sets limits on what the assistant may give you.
Common mistakes
- Judging progress by completed tasks. Count what you can do without help, not what you have submitted.
- Reading instead of writing. Looking over a solution is not practice. Typing your own version is.
- Trusting passing output. A program can run and still be wrong for inputs you did not try.
- Treating the assistant as an all-or-nothing tool. You can use it for explanation and review while doing the core work yourself.
- Feeling guilty about any use. The goal is deliberate use, not avoidance.
Exercises
Exercise
A learner pastes five assignments into an AI assistant, gets working code for each, and all tests pass. Name two reasons this does not show that the learner can program, and one quick check the learner could run to find out.
Show answer
First, the passing tests describe the code, not the learner. The learner did not have to recall or produce anything. Second, recognizing correct code feels like understanding it, which hides gaps in recall. A quick check is to close the assistant and the earlier solutions, then write one of the functions from a blank file, or predict the output of a short snippet before running it. If the learner cannot do either, the skill has not formed yet.
Exercise
Sort these requests into "likely supports learning" and "likely undermines learning": (a) "Write a function that returns the median of a list." (b) "Here is my median function and its wrong output. Ask me one question to help me find the bug." (c) "Explain this ImportError." (d) "Here is my working solution. What could I improve?"
Show answer
(a) undermines learning, because it asks for the finished answer before any attempt. (b) supports learning, because it follows an attempt and keeps the reasoning with the learner. (c) usually supports learning, because it removes unproductive struggle with a tool message and does not replace the core problem. (d) supports learning, because it asks for a review after the learner produced working code.
Exercise
Run the count_vowels example from this chapter. Before you run it, write down the number you expect for "Learning with AI". Then explain in one sentence why .lower() is needed.
Show answer
The expected result is 6, from the vowels e, a, i, i, A and I. The call to .lower() is needed because the check ch in "aeiou" only matches lowercase letters, so without it the capital A and I would not be counted and the result would be 4.