"I Would Have Written My Code Differently": Beginners Struggle to Understand LLM-Generated Code

Yangtian Zi, Luisa Li, Arjun Guha, Carolyn Jane Anderson, Molly Q. Feldman · DOI

Abstract

While Large Language Models (LLMs) can generate code in seconds, beginning programmers often lack the "code literacy" required to review and debug it. This study of introductory computer science (CS1) students found a startlingly low success rate of 32.5% in comprehending LLM-generated code, highlighting a massive gap between a student's ability to prompt an AI and their ability to understand its output. The findings suggest that the "Review" step in AI-assisted coding is a significant pedagogical hurdle for novices, potentially leading to an "illusion of competence."

Introduction: The Review Bottleneck

In professional software engineering, the workflow for AI-assisted coding is typically "Prompt -> Generate -> Review -> Integrate." However, in computer science education, the focus has largely been on the first two steps: how to write better prompts. This paper argues that we are ignoring a critical pedagogical risk: the "illusion of competence." If a student can prompt an LLM to solve a homework problem but cannot read or explain the resulting code, they aren't actually learning to program. This study investigates whether beginners are actually equipped to perform the "Review" step—a prerequisite for using LLMs safely and effectively in a learning environment.

Methods and Experimental Design

The researchers conducted a controlled lab-based user study with 32 CS1 students. Each participant completed five tasks, each structured into three distinct phases to isolate different aspects of comprehension.

The three-phase study design: Prompt Comprehension, Code Comprehension, and Reflection.
  1. Prompt Comprehension (Part A): Students read a natural language description of a programming problem and predicted the output for three specific inputs. This established whether they understood the goal of the task.
  2. Code Comprehension (Part B): Students were shown LLM-generated Python code intended to solve that same problem. They had to predict the code's output for the same inputs. Crucially, the code was sometimes intentionally buggy or written in a complex style.
  3. Reflection (Part C): Students compared their predictions against the ground truth and provided qualitative feedback.

The study utilized a curated dataset of 48 CS1-level problems. For each problem, eight code variations were generated using Code Llama, categorized by correctness, the presence of comments, and stylistic complexity (e.g., "Pythonic" idioms like list comprehensions vs. basic loops).

Key Results: The Comprehension Gap

The study found that students were nearly twice as likely to understand the natural language prompt (59.3% success) as they were to understand the resulting code (32.5% success). This discrepancy highlights that comprehension, not prompting, is the primary bottleneck for novices.

Comparison of student performance in predicting outputs for problem descriptions (Part A) versus actual LLM-generated code (Part B).

Automation Bias and Bug Blindness

A major finding was the prevalence of automation bias. Students frequently predicted the intended output of the function rather than what the code in front of them actually did. They assumed the AI was correct, leading them to overlook bugs. In fact, 90.6% of participants assumed the code was correct at least once, even when their own trace of the logic should have shown them otherwise. When the LLM produced incorrect (buggy) code, the success rate plummeted significantly.

The "Pythonic" Disconnect

LLMs are trained on professional repositories and tend to produce idiomatic, "Pythonic" code (e.g., words[::-1]). CS1 students, however, are typically taught explicit loops first. Many students reported that the AI's "clever" one-liners were unreadable to them. Approximately 43.8% of participants specifically commented on the unfamiliar style of the AI code, with one student noting, "I would have written my code differently... probably every single other programmer at my level [would too]."

Discussion and Future Directions

The study suggests that the move toward "natural language programming" via LLMs might inadvertently create new accessibility barriers. For instance, non-native English speakers struggled significantly more with the Prompt Comprehension phase.

To address these issues, the authors suggest that CS1 curricula need to shift from a "writing-first" to a "reading-first" or "comprehension-heavy" approach. They propose developing "LLM-aware" teaching strategies that specifically train students to scrutinize AI output and recognize common "Pythonic" idioms early on. Future research should also explore how different LLMs (like GPT-4 or Claude) vary in the "readability" of the code they generate for novices, as this could impact the effectiveness of AI as a learning tool.

Summary updated

BibTeX
@inproceedings{zi2025i,
  author = {Yangtian Zi and Luisa Li and Arjun Guha and Carolyn Jane Anderson and Molly Q. Feldman},
  title = {{"I Would Have Written My Code Differently": Beginners Struggle to Understand LLM-Generated Code}},
  booktitle = {SIGSOFT FSE Companion},
  year = {2025},
  doi = {10.1145/3696630.3731663},
}
Figure