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

  • Sara Nurollahian
  • , Matthew Hooper
  • , Adriana Salazar
  • , Eliane Wiese

Research output: Chapter in Book/Report/Conference proceedingConference contributionpeer-review

7 Scopus citations

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.

Original languageEnglish
Title of host publicationSIGCSE 2023 - Proceedings of the 54th ACM Technical Symposium on Computer Science Education
PublisherAssociation for Computing Machinery, Inc
Pages542-548
Number of pages7
ISBN (Electronic)9781450394314
DOIs
StatePublished - Mar 2 2023
Event54th ACM Technical Symposium on Computer Science Education, SIGCSE 2023 - Toronto, Canada
Duration: Mar 15 2023Mar 18 2023

Publication series

NameSIGCSE 2023 - Proceedings of the 54th ACM Technical Symposium on Computer Science Education
Volume1

Conference

Conference54th ACM Technical Symposium on Computer Science Education, SIGCSE 2023
Country/TerritoryCanada
CityToronto
Period03/15/2303/18/23

Keywords

  • anti-patterns
  • code readability
  • code smell
  • code structure
  • conditional statements
  • discourse rules
  • exclusive ifs
  • novice code
  • programming patterns
  • sequential if statements with exclusive conditions
  • static code analyzer

Fingerprint

Dive into the research topics of 'Use of an Anti-Pattern in CS2: Sequential if Statements with Exclusive Conditions'. Together they form a unique fingerprint.

Cite this