PDA

View Full Version : Suggestion - Switch case


tumami
05-13-2014, 04:42 PM
Hello, i have an suggestion:

Implement the switch command. It is similar to "if/else".

Example using If/Else.

If students = 90
do anything

Else
If students = 80
do anything

Else
If students = 70
do anything

Else
if students = 60
do anything

Else
if students = 50
do anything

Example using Switch:

Switch students
Case 90: do anything
Case 80: do anything
Case 70: do anything
Case 60: do anything
Case 50: do anything

and down of the last case, a button to add a new case.

Its a good idea?

djslater107
05-14-2014, 10: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.

jrrTolkien
05-14-2014, 07:25 PM
It may still be a good idea to put it in, anyway. I personally find the nested loops easier, but that may change with the construction of the switch.

-Jrr

MrMoke
05-14-2014, 10:43 PM
I agree that it may be an unnecessary level of detail for an entry level course that would be a student's first exposure to the kind of logical thinking that is required to succeed in System Design.

I also agree that it would be difficult to implement in a Drag-n-Drop environment. I suppose that you could drag one in that had a "Default" built-in. And I suppose that it would be possible to add "Cases" that had a default "Break" with a "more.." dropdown where you could select "yes" or "no", but the student would have to remember to set it, and it might be confusing to troubleshoot.

Nested "Ifs" are sometimes required, but can be a crutch for the novice. For example, my version of the "Memory Game" that I posted in a video in another thread handled from 1 to 10 different buttons based on user input, and only used a single nested "If" that determined whether to restart or quit the game.

Save it for Java.