What is it about?
Students must learn to write code that is not only functional but also uses appropriate structures that communicate the programmer's intentions clearly and promote readability. For instance, when checking exclusive conditions sequentially (e.g., (size<10), (size>=10)), a better structure to use is if-else-if or if-else, instead of if-if because else structures communicate the runtime exclusivity of the conditions and highlight related conditions. Previous research has shown that many students use less readable structures, and some researchers have concluded that students' use of less readable structures is due to knowledge gaps about the correct structure. To investigate this issue, we built a detector that identifies instances of exclusive if-if as well as exclusive if-else-if. We ran the detector on programming homework submissions from almost 130 pairs of students in the intro to algorithm and data structure course. We found that students' use of exclusive if-if varied based on assignments, with the prevalence ranging from 3% to 50% of submissions. Therefore, since different assignments lend themselves to different usage of structures, researchers need to know the assignment details before making conclusions about the prevalence of different structural issues in student code. Furthermore, exclusive if-if did not preclude student use of exclusive if-else-if: more than half of the students had at least one submission having both instances. Therefore, many students who used the less readable structures knew how to use the appropriate one correctly. Hand-inspection of student code with exclusive if-if indicated that providing feedback on the structure is often straightforward, but sometimes students' use of exclusive if-if is due to larger issues with understanding or abstraction. In these cases, structural feedback alone may not solve the larger issues with code.
Featured Image
Photo by Caspar Camille Rubin on Unsplash
Why is it important?
We have developed a detector that uses both Z3, a satisfiability module solver, and the AST of a code to identify sequential if statements with exclusive conditions (exclusive ifs). While existing educational code analyzers use the code AST to identify problematic structures, more complex anti-patterns cannot always be identified with the AST alone. We ran the detector on programming submissions from 130 pairs of students in an Intro to Algorithm and Data Structure class and found that their use of exclusive ifs varied depending on the assignment. This suggests that researchers examining common anti-patterns in student programs should consider assignment details before drawing conclusions, as some assignments provoke more usage of specific anti-patterns. In addition to exclusive if-ifs, we also examined students' use of the exclusive else-if pattern and found that many submissions have instances of both, indicating that those students knew how to correctly use the else-if. Therefore, the use of anti-patterns could have other explanations beyond knowledge gaps. Focusing solely on anti-patterns when evaluating student code quality may not provide a complete picture of their knowledge. Further inspection of flagged code revealed that some students' use of anti-patterns was an indication of larger issues with understanding or abstraction. Therefore, researchers should be cautious when providing automated feedback on code structure to students. Lastly, we discovered an instructional gap in readily available online resources: we could not find any explanation of exclusivity or guidance on when to use if-if vs. if-else-if.
Perspectives
Read the Original
This page is a summary of: Use of an Anti-Pattern in CS2: Sequential if Statements with Exclusive Conditions, March 2023, ACM (Association for Computing Machinery),
DOI: 10.1145/3545945.3569744.
You can read the full text:
Contributors
The following have contributed to this page