Use of an Anti-Pattern in CS2: Sequential if Statements with Exclusive Conditions
Open Access
- 2 March 2023
- conference paper
- Published by Association for Computing Machinery (ACM)
- p. 542-548
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 student's 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: across assignments, up to 34% of the 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.Keywords
Funding Information
- National Science Foundation (NSF) award SHF 1948519 (1948519)
This publication has 14 references indexed in Scilit:
- How Teachers Would Help Students to Improve Their Code2019
- Understanding semantic style by analysing student code2018
- Code Quality Issues in Student Programs2017
- Teaching Students to Recognize and Implement Good Coding Style2017
- Static analysis of source code written by novice programmers2017
- An Empirical Study of Iterative Improvement in Programming Assignments2015
- Integrating pedagogical code reviews into a CS 1 course2009
- Programming studio2007
- But My Program Runs! Discourse Rules for Novice ProgrammersJournal of Educational Computing Research, 1986
- Empirical Studies of Programming KnowledgeIEEE Transactions on Software Engineering, 1984