logo
Loading...
Use of an Anti-Pattern in CS2: Sequential if Statements with Exclusive Conditions
Computer ScienceProceedings of the 54th ACM Technical Symposium on Computer Science Education V. 1 (SIGCSE 2023)

Use of an Anti-Pattern in CS2: Sequential if Statements with Exclusive Conditions

S. Nurollahian, M. Hooper, et al.

This research, conducted by Sara Nurollahian, Matthew Hooper, Adriana Salazar, and Eliane Wiese, uncovers a prevalent anti-pattern in student coding practices. The use of sequential if statements over else-if or else statements was observed in various CS2 homework submissions, revealing significant implications for students' understanding of logic and abstraction.... show more
Abstract
How can we teach students to use more readable code structures? How common is it for students to choose less readable (but still functional) alternatives? We explore these questions for a specific anti-pattern: using sequential if statements when conditions are exclusive (rather than using else-if or else). We created and validated an automated detector to identify this anti-pattern in students’ code. Running the detector on 1,764 homework submissions (from 270 students in a CS2 class on data structures and algorithms) showed that this anti-pattern was common and varied by assignment: across 12 assignments, 3% to 50% of submissions used sequential ifs for exclusive cases. However, using this anti-pattern did not preclude using else-ifs: for one assignment, 34% of submissions used both forms. Further, students used sequential if statements in surprising ways, such as checking a condition and then the negation of that condition, indicating a more novice level of understanding than expected for an intermediate course. Hand-inspection of the detector-flagged cases suggests that sequential ifs for exclusive cases may be a code smell that can indicate larger problems with logic and abstraction.
Publisher
Proceedings of the 54th ACM Technical Symposium on Computer Science Education V. 1 (SIGCSE 2023)
Published On
Mar 15, 2023
Authors
Sara Nurollahian, Matthew Hooper, Adriana Salazar, Eliane Wiese
Tags
student codeanti-patternsequential if statementselse-if statementsCS2 classlogic problemsabstraction issues
Listen, Learn & Level Up
Over 10,000 hours of research content in 25+ fields, available in 22+ languages.
No more digging through PDFs, just hit play and absorb the world's latest research in your language, on your time.
listen to research audio papers with researchbunny