Alice Community  

Go Back   Alice Community > Alice 2 > Suggestion Box

Reply
 
Thread Tools Display Modes
Suggestion - Switch case
Old
tumami
Junior Member
 
Status: Offline
Posts: 7
Join Date: Nov 2013
Location: Argentina
Lightbulb Suggestion - Switch case - 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?
Attached Images
File Type: jpg switch.jpg (11.6 KB, 9 views)


Argentina !
   
Reply With Quote
Switch statement
Old
djslater107
Administrator
 
Status: Offline
Posts: 144
Join Date: Jan 2007
Default Switch statement - 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.


Don Slater
Alice Team
Carnegie Mellon University
   
Reply With Quote
Well,
Old
jrrTolkien
Senior Member
 
jrrTolkien's Avatar
 
Status: Offline
Posts: 166
Join Date: Feb 2014
Location: Middle-Earth (Merrimack, NH)
Thumbs up Well, - 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
   
Reply With Quote
I'm with Don
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 500
Join Date: Sep 2007
Location: Austin, Texas
Default I'm with Don - 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.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.