The prompt coding mental model

The prompt coding mental model

3 min read · January 09, 2025

I’ve been thinking for a while about the mental models students have when learning to program. It occurred to me while considering something completely unrelated. Over the years, I’ve noticed a pattern in how some students approach programming. For some reason, certain students write code out of order and perform variable assignments, expecting the program to work in the end.

I couldn’t find a real example, but here’s a made-up one. Suppose you need to write a program to calculate 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

This example highlights two points:

  1. The student knows that print prints output, but expects the distance variable to be printed only after the whole program runs.
  2. The student gets the formula right, but expects the distance variable to be updated after each iteration of the loop.

It’s not uncommon for students to come to me genuinely surprised when their code doesn’t work. I suspect their mental model might align more with how languages like Prolog work. But I also believe there’s another factor at play. I’ve noticed this type of issue happening more frequently in recent years, which led me to form my hypothesis, which I’m calling the prompt coding mental model.

When you interact with an AI assistant, you don’t have to worry about the order in which you phrase things. You simply ask for what you want, and the assistant figures out the details. I suspect some students treat programming the same way—they write a series of instructions in no particular order and hope the computer will make sense of it. They don’t fully grasp the concepts of control flow and state, which is why I’m more convinced that developing an IDE designed for beginners, like the one I’ve discussed in a previous post, could help them understand these concepts better.

This is just a hypothesis at this point, and I don’t have data to support it. But I believe it’s worth exploring further.