Home
The prompt coding mental model

The prompt coding mental model

3 min read · January 09, 2025

I have been thinking for a while about the mental models that students have when learning to program. As it tends to happen, I was thinking about something completely unrelated when it occurred to me. Throughout the years, I have noticed a pattern in the way some students approach programming. For some reason, some students write lines of code in no particular order and perform a series of variable assignments expecting that in the end, the code will work.

I tried to find a real example, but couldn’t. So here’s a made-up one. Suppose you have to write a program that calculates the total distance between a sequence of ten 2D points entered by the user. The student writes the following code:

print(distance)

distance = (x2-x1)**2 + (y2-y1)**2

x1 = float(input("Enter x: "))
y1 = float(input("Enter y: "))
for i in range(8):
    x2 = float(input("Enter x: "))
    y2 = float(input("Enter y: "))
    x1 = x2
    y1 = y2

I wanted to illustrate the following points with this example:

  1. The student knows that print is used to print the output to the console, but they were somehow expecting that the distance variable would be printed only after the whole program was executed;
  2. The student gets the formula right, but they were expecting that the distance variable would be updated after each iteration of the loop.

It is not uncommon for them to come to me genuinely surprised that their code is not working. Maybe their mental model is closer to that o languages like Prolog, but I realized that there is another possibility. I noticed that this kind of problem started to happen more frequently in the last few years. That’s when I came up with my hypothesis. I’m calling it the prompt coding mental model.

When you send a prompt to an AI assistant, you don’t have to worry too much about the order in which you say things. You just say what you want in broad terms, and the assistant will (hopefully) figure out the rest. I think some students are treating programming in the same way. They write a series of instructions in no particular order, and hope that the computer will figure out the rest. They don’t understand at first the concept of control flow and state. That’s why I’m more confident that developing a IDE specifically designed for beginners could help them understand these concepts better.

Again, this is just a hypothesis I am working on. I don’t have data to back it up, but I think it may be worth exploring.