Search papers, labs, and topics across Lattice.
This study utilized eye-tracking technology to analyze how novice developers comprehend different Python repetition structures, including for loops, while loops, recursion, and list comprehensions. The results indicated that while loops and list comprehensions significantly increased cognitive load, as evidenced by longer fixation durations and higher regression counts, compared to for loops. These findings highlight the varying cognitive demands of Python constructs, which can inform practices in code readability and developer onboarding.
While loops and list comprehensions can double cognitive load for novice developers compared to for loops, revealing critical insights for code comprehension and maintainability.
Code comprehension is central to software maintenance and evolution, yet different Python repetition structures may impose distinct cognitive demands. We conducted a controlled eye-tracking experiment with 32 undergraduate students with prior Python experience to compare comprehension of for loops, while loops, recursion, and list comprehensions (LCs). Participants solved six comprehension tasks in a Latin Square design while we measured completion behavior and eye-tracking metrics over full snippets and construct-specific Areas of Interest (AOIs). for loops showed the lowest visual effort. Relative to for, while loops increased AOI fixation duration by up to 97% and regression count by 114%, with regressions concentrated around counter management. Recursion showed a descriptive 50% increase in regressions, mainly between the base case and recursive call. LCs increased AOI time by 62.5% and fixation duration by 80.9%, with horizontal regressions suggesting dense token-by-token parsing. LC comparisons yielded the clearest statistically significant pairwise differences, while the combined comparison of all non-for structures was significant across all eye-tracking metrics. These findings provide process-level evidence that Python repetition structures induce distinct visual-effort patterns, with implications for readability, code review, refactoring, onboarding, and maintainability.