www.digitalmars.com         C & C++   DMDScript  

D - Yet another switch idea

reply J Anderson <REMOVEanderson badmama.com.au> writes:
As I see it there are 3 camps on the default switch issue

No exception (C)
Mandatory default
Default exception

This is an attempt to go half-way between the No exception and default 
exception camps.

This is probably not a new idea, but here goes.

Default exception occurs when the user write default: with nothing after it.

val = 10;

switch (val)
{
case 5: break;
case 6: break;
default: //causes exception
}

switch (val)
{
case 5: break;
case 6: break;
default: break; //no exception
}

switch (val)
{
case 5: break;
case 6: break;
//no exception
}

Con: The problem with this is that people won't be compelled to use the 
"cool" default exception and so it may become hidden under the blanket.

-Anderson
Dec 10 2003
parent Berin Loritsch <bloritsch d-haven.org> writes:
J Anderson wrote:

 As I see it there are 3 camps on the default switch issue
 
 No exception (C)
 Mandatory default
 Default exception
 
 This is an attempt to go half-way between the No exception and default 
 exception camps.

-1. I don't like the idea because the behavior is not intuitive. Perhaps a "bounded_switch" would be a nice way to make it obvious what will happen when the default case is not handled. Maybe an additional parameter: switch(val) : bounded {} switch(val) : unbounded {} switch(val, true); // bounded == true switch(val, false); // bounded == false Anyhoo, I am not going to spend too much more energy on this, it is very clear that Walter will do what he will do. Since I am not writing the compiler, there is only so much say I have in the matter.
Dec 10 2003