Table of Contents
Fetching ...

"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

TL;DR

CS1 students struggle to understand LLM-generated code, despite being able to interpret problem prompts. Using a lab study with 32 participants and Code Llama-produced code across 40 tasks, the authors find a per-task code comprehension success of $32.5\%$ versus $59.3\%$ for prompt comprehension, with many correct prompts paired with incorrect code. Non-native English speakers face a notable disadvantage in prompt comprehension, while code comprehension differences across demographics are minimal; automation bias leads students to overestimate code correctness. The results motivate LLM-aware pedagogy and beginner-focused tooling to improve code-reading and evaluation skills, ensuring AI-assisted programming benefits CS1 learners rather than leaving them with a false sense of competence.

Abstract

Large language models (LLMs) are being increasingly adopted for programming work. Prior work shows that while LLMs accelerate task completion for professional programmers, beginning programmers struggle to prompt models effectively. However, prompting is just half of the code generation process -- when code is generated, it must be read, evaluated, and integrated (or rejected). How accessible are these tasks for beginning programmers? This paper measures how well beginners comprehend LLM-generated code and explores the challenges students face in judging code correctness. We compare how well students understand natural language descriptions of functions and LLM-generated implementations, studying 32 CS1 students on 160 task instances. Our results show a low per-task success rate of 32.5\%, with indiscriminate struggles across demographic populations. Key challenges include barriers for non-native English speakers, unfamiliarity with Python syntax, and automation bias. Our findings highlight the barrier that code comprehension presents to beginning programmers seeking to write code with LLMs.

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

TL;DR

CS1 students struggle to understand LLM-generated code, despite being able to interpret problem prompts. Using a lab study with 32 participants and Code Llama-produced code across 40 tasks, the authors find a per-task code comprehension success of versus for prompt comprehension, with many correct prompts paired with incorrect code. Non-native English speakers face a notable disadvantage in prompt comprehension, while code comprehension differences across demographics are minimal; automation bias leads students to overestimate code correctness. The results motivate LLM-aware pedagogy and beginner-focused tooling to improve code-reading and evaluation skills, ensuring AI-assisted programming benefits CS1 learners rather than leaving them with a false sense of competence.

Abstract

Large language models (LLMs) are being increasingly adopted for programming work. Prior work shows that while LLMs accelerate task completion for professional programmers, beginning programmers struggle to prompt models effectively. However, prompting is just half of the code generation process -- when code is generated, it must be read, evaluated, and integrated (or rejected). How accessible are these tasks for beginning programmers? This paper measures how well beginners comprehend LLM-generated code and explores the challenges students face in judging code correctness. We compare how well students understand natural language descriptions of functions and LLM-generated implementations, studying 32 CS1 students on 160 task instances. Our results show a low per-task success rate of 32.5\%, with indiscriminate struggles across demographic populations. Key challenges include barriers for non-native English speakers, unfamiliarity with Python syntax, and automation bias. Our findings highlight the barrier that code comprehension presents to beginning programmers seeking to write code with LLMs.
Paper Structure (19 sections, 4 figures, 4 tables)

This paper contains 19 sections, 4 figures, 4 tables.

Figures (4)

  • Figure 1: Two implementations of reverseWords.
  • Figure 2: Procedure of a task. Prompt comprehension presents a description collected from Nguyen et al. charlie and three inputs. A participant enters their expected output for the described function given the description. Code comprehension presents code generated for the problem by an LLM and the same set of inputs, but asks for the output of the code. Reflection presents the correct answer for both parts and prompts the user to review their answer. For prompt comprehension responses, a response is correct () if it matches the expected output or wrong ($\times$) otherwise. For code comprehension responses, a matching response to the actual output is said to be consistent ($=$); a non-matching response is inconsistent ($\not=$) to the actual output of the code.
  • Figure 3: The Study Interface.
  • Figure 4: Counts and percentages of per-part success rates for prompt comprehension (Prompt) and code comprehension (Code) under different code correctness conditions: (a) all task instances, (b) tasks with correct code, and (c) tasks with incorrect code.