TL;DR
This paper evaluates whether Large Language Models (LLMs) can generate high-quality code explanations to help novice programmers learn. In a study involving nearly 1,000 introductory computer science students, explanations generated by GPT-3 were rated as significantly more accurate and easier to understand than explanations written by the students' own peers.
What Problem Does This Paper Address?
Learning to read and explain code is a foundational skill in computer science, strongly correlating with a student's ability to write code. However, novice programmers frequently struggle to articulate what a piece of code does.
While providing high-quality, personalized example explanations is an excellent pedagogical tool, it doesn't scale well in massive introductory courses (often exceeding 1,000 students). Instructors simply don't have the time to generate them on demand. While "learnersourcing"—asking students to generate explanations for each other—is one solution, student-generated content can vary wildly in quality. The authors investigate whether LLMs can solve this scalability problem by "robosourcing" reliable, high-quality code explanations on demand.
Methods
The researchers integrated their study into a first-year C programming course at The University of Auckland. The experiment was split into two lab sessions:
- Lab A (Generation): Students were given three simple C functions (e.g., finding the largest value in an array, counting zeros) and asked to write a short description of their intended purpose. Concurrently, the researchers used GPT-3 (
text-davinci-002) to generate explanations for the same functions. - Lab B (Evaluation): Two weeks later, the researchers selected a stratified sample of 27 student explanations (based on length) and 27 GPT-3 explanations. Each student was randomly assigned four explanations from this pool of 54 to evaluate on a 5-point Likert scale measuring understandability, accuracy, and length.
The authors used Mann-Whitney U tests to statistically compare the student-authored and LLM-authored explanations, alongside a thematic analysis of open-ended feedback to understand what characteristics students value in an explanation.
Datasets
The study did not use standard external benchmarks. Instead, it collected a custom dataset from the course enrollment:
- Student Submissions: 963 unique code explanations per function collected during Lab A.
- LLM Submissions: 27 explanations generated by GPT-3 (9 per function).
- Evaluations: Quantitative ratings and open-ended feedback from 954 participating students.
Key Insights and Ideas
- The Line-by-Line Preference: Novice students strongly prefer detailed, line-by-line ("multi-structural") explanations over high-level, abstract ("relational") summaries.
- The Student-Instructor Mismatch: Computing education literature traditionally favors abstract summaries as a sign of higher-level understanding. However, this study reveals a mismatch: novices find line-by-line breakdowns much more useful for learning because abstract summaries often omit details that aren't yet obvious to a beginner.
- Consistency Wins: GPT-3 naturally followed a highly structured, predictable format (stating the purpose, analyzing the code, and describing the return output), which students found easier to digest than the highly variable formats of peer explanations.
Key Results
The quantitative analysis revealed a clear preference for AI-generated content:
- Understandability: GPT-3 explanations achieved a significantly higher mean rating (4.12) compared to student-generated ones (3.75).
- Accuracy: LLM explanations were rated as more accurate summaries of the code (Mean: 4.00) than student explanations (Mean: 3.78).
- Effect Size: The Common-Language Effect Size (CLES) indicated a 60% probability that a randomly chosen LLM explanation would be rated as easier to understand than a randomly chosen student explanation.
- Length: Interestingly, there was no statistically significant difference in the actual character length or the perceived ideal length between the two groups, proving that the LLM's higher ratings were due to content quality rather than brevity or verbosity.
Limitations and Future Work
The authors note several limitations that pave the way for future research:
- Novice-Only Perspective: The evaluations were conducted entirely by novices. Advanced students or instructors might value abstract summaries more than line-by-line breakdowns and rate the explanations differently.
- Simple, Correct Code: The study only used simple, bug-free functions. How LLMs handle explaining complex, multi-file codebases or code containing logical errors remains an open question.
- Older Model: The study utilized
text-davinci-002. State-of-the-art models (like GPT-4) would likely yield even higher performance.
Moving forward, the authors suggest exploring token-economy systems where students are given a limited number of AI explanation requests and must "earn" more by writing their own hand-crafted explanations, preventing over-reliance on AI tools.
Summary updated