View Single Post
Switch statement
Status: Offline
Posts: 164
Join Date: Jan 2007
Default Switch statement - 05-14-2014, 11:05 AM

Thank you for your interest and your suggestion... We gave considered implementing the Switch statement in Alice and have decided against it.

It is a code construct that we are not sure should be introduced to beginning programmers. There are good reason's to use the switch, but a programmer should be making the choice based on an understanding of what they are trying to accomplish in their task. Beginners, by definition, do not have that experience to make an informed choice.

It adds no functionality that cannot reasonably be duplicated by using nested if statements.

It's reliance on the break statement can be argued as being bad coding style (your mileage will vary and I do not mean to get into a religious war), but more importantly, can lead a beginner into a deep rabbit hole of programming errors that are easy to create and hard to find.

From a practical point of view, implementing the switch in a drag and drop environment is a very complex problem. Drag the switch in, then how many cases should be shown, or does suddenly the case statement appear in the control panel. And the break also has to appear, because not every Case requires a break.

Finally, we find ourselves in good company, as the switch statement is not part of the AP Computer Science testable subset. In other words, APCS students will not be tested on the switch statement. They can use it during the free-repsonse portion of the exam, but they do so at heir own risk.

Don Slater
Alice Team
Carnegie Mellon University
Reply With Quote