Activity 01
Pair Refactor: If-Else to Case
Provide students with a nested if-else menu handler for a simple game. In pairs, they rewrite it using a case statement, test inputs, and note changes in line count and clarity. Pairs then swap code for peer review.
Compare the readability and efficiency of case statements versus nested if-else structures.
Facilitation TipDuring Pair Refactor, pair students with different prior knowledge to encourage peer teaching and immediate feedback on their refactoring choices.
What to look forPresent students with a short code snippet containing a series of nested if-else statements that could be replaced by a case statement. Ask them to rewrite the snippet using a case statement and explain one advantage of their new version.