Jump to page: 1 2 3
Thread overview
[Suggestion] Alternative switch/case syntax
Jan 29, 2004
Stewart Gordon
Jan 29, 2004
J Anderson
Jan 29, 2004
C
Jan 29, 2004
Matthew
Jan 30, 2004
Stewart Gordon
Jan 30, 2004
Vathix
Jan 30, 2004
Olaf Rogalsky
OT: top posting (was Re: [Suggestion] Alternative switch/case syntax)
please snip Re: OT: top posting (was Re: [Suggestion] Alternative switch/case syntax)
Feb 01, 2004
Mark T
Jan 29, 2004
Sadjuuk Kar
Jan 29, 2004
Sadjuuk Kar
Jan 29, 2004
Stephan Wienczny
Jan 29, 2004
Matthew
Jan 29, 2004
Ilya Minkov
Jan 30, 2004
kinghajj
Jan 30, 2004
Stewart Gordon
Jan 29, 2004
Matthew
Jan 30, 2004
Andy Friesen
Jan 30, 2004
kinghajj
Jan 30, 2004
J Anderson
Jan 30, 2004
Andy Friesen
May 19, 2004
LordSyl
May 21, 2004
Stewart Gordon
January 29, 2004
In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:

	switch (qwert) {
		case 1 {
			yuiop = 3;
		}
		case 2 {
			yuiop = 4;
		}
		case 3, 4, 5 {
			yuiop = 5;
		}
	}

(Note no colons)

The idea:
- Having the case clauses as block statements seems the logical thing to me.

- Declarations/initialisations local to case clauses - I know you can do

	case 1: {
		Asdfg hjkl = new Asdfg;
		// ...
	} break;

but I still think my idea is neater.

- When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter.  Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed.  Maybe an 'else' could be used to override this, e.g.

	switch (qwert) {
		case 0, 5, 10 {
			// do stuff if qwert is 0, 5 or 10
		} else case 1..9 {
			/* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
			 * (or should this be semi-inclusive like array
			 * slicing?)
			 */
		}

		case 6..13 {
			/* do stuff if qwert is 6..13, even if a
			 * previous case matched
			 */
		}

		default {
			// this would still mean do stuff if  none match
		}
	}

Nesting could also be allowed, for a bit of syntactic sugar:

	switch (qwert) {
		case 0..10 {
			// do something

			case 4 {
				// do something more specific
			}

			// now do something else
		}
	}

What do you think?

Stewart.

-- 
My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment.  Please keep replies on the 'group where everyone may benefit.
January 29, 2004
Stewart Gordon wrote:

> In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
>
>     switch (qwert) {
>         case 1 {
>             yuiop = 3;
>         }
>         case 2 {
>             yuiop = 4;
>         }
>         case 3, 4, 5 {
>             yuiop = 5;
>         }
>     }
>
> (Note no colons)
>
> The idea:
> - Having the case clauses as block statements seems the logical thing to me.
>
> - Declarations/initialisations local to case clauses - I know you can do
>
>     case 1: {
>         Asdfg hjkl = new Asdfg;
>         // ...
>     } break;
>
> but I still think my idea is neater.
>
> - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter.  Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed.  Maybe an 'else' could be used to override this, e.g.
>
>     switch (qwert) {
>         case 0, 5, 10 {
>             // do stuff if qwert is 0, 5 or 10
>         } else case 1..9 {
>             /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
>              * (or should this be semi-inclusive like array
>              * slicing?)
>              */
>         }
>
>         case 6..13 {
>             /* do stuff if qwert is 6..13, even if a
>              * previous case matched
>              */
>         }
>
>         default {
>             // this would still mean do stuff if  none match
>         }
>     }
>
> Nesting could also be allowed, for a bit of syntactic sugar:
>
>     switch (qwert) {
>         case 0..10 {
>             // do something
>
>             case 4 {
>                 // do something more specific
>             }
>
>             // now do something else
>         }
>     }
>
> What do you think?
>
> Stewart.
>

Oh no, not switch statements again.  And this was my idea ;)

-- 
-Anderson: http://badmama.com.au/~anderson/
January 29, 2004
You could create an enhanced extended switch.  Then you could have a basic switch for backward compatability and more complex power switch statement althogh the syntax and name could be slightly different.

In article <bvb6lc$1t7a$1@digitaldaemon.com>, Stewart Gordon says...
>
>In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
>
>	switch (qwert) {
>		case 1 {
>			yuiop = 3;
>		}
>		case 2 {
>			yuiop = 4;
>		}
>		case 3, 4, 5 {
>			yuiop = 5;
>		}
>	}
>
>(Note no colons)
>
>The idea:
>- Having the case clauses as block statements seems the logical thing to me.
>
>- Declarations/initialisations local to case clauses - I know you can do
>
>	case 1: {
>		Asdfg hjkl = new Asdfg;
>		// ...
>	} break;
>
>but I still think my idea is neater.
>
>- When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter.  Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed.  Maybe an 'else' could be used to override this, e.g.
>
>	switch (qwert) {
>		case 0, 5, 10 {
>			// do stuff if qwert is 0, 5 or 10
>		} else case 1..9 {
>			/* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
>			 * (or should this be semi-inclusive like array
>			 * slicing?)
>			 */
>		}
>
>		case 6..13 {
>			/* do stuff if qwert is 6..13, even if a
>			 * previous case matched
>			 */
>		}
>
>		default {
>			// this would still mean do stuff if  none match
>		}
>	}
>
>Nesting could also be allowed, for a bit of syntactic sugar:
>
>	switch (qwert) {
>		case 0..10 {
>			// do something
>
>			case 4 {
>				// do something more specific
>			}
>
>			// now do something else
>		}
>	}
>
>What do you think?
>
>Stewart.
>
>-- 
>My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment.  Please keep replies on the 'group where everyone may benefit.


January 29, 2004
You could create an enhanced extended switch.  Then you could have a basic switch for backward compatability and more complex power switch statement althogh the syntax and name could be slightly different.

In article <bvb6lc$1t7a$1@digitaldaemon.com>, Stewart Gordon says...
>
>In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
>
>	switch (qwert) {
>		case 1 {
>			yuiop = 3;
>		}
>		case 2 {
>			yuiop = 4;
>		}
>		case 3, 4, 5 {
>			yuiop = 5;
>		}
>	}
>
>(Note no colons)
>
>The idea:
>- Having the case clauses as block statements seems the logical thing to me.
>
>- Declarations/initialisations local to case clauses - I know you can do
>
>	case 1: {
>		Asdfg hjkl = new Asdfg;
>		// ...
>	} break;
>
>but I still think my idea is neater.
>
>- When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter.  Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed.  Maybe an 'else' could be used to override this, e.g.
>
>	switch (qwert) {
>		case 0, 5, 10 {
>			// do stuff if qwert is 0, 5 or 10
>		} else case 1..9 {
>			/* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
>			 * (or should this be semi-inclusive like array
>			 * slicing?)
>			 */
>		}
>
>		case 6..13 {
>			/* do stuff if qwert is 6..13, even if a
>			 * previous case matched
>			 */
>		}
>
>		default {
>			// this would still mean do stuff if  none match
>		}
>	}
>
>Nesting could also be allowed, for a bit of syntactic sugar:
>
>	switch (qwert) {
>		case 0..10 {
>			// do something
>
>			case 4 {
>				// do something more specific
>			}
>
>			// now do something else
>		}
>	}
>
>What do you think?
>
>Stewart.
>
>-- 
>My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment.  Please keep replies on the 'group where everyone may benefit.


January 29, 2004
Why do people put thier responses at the bottom :P.  All that scrolling makes me dizzy.

C
"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message
news:bvb7ip$1umk$2@digitaldaemon.com...
> Stewart Gordon wrote:
>
> > In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
> >
> >     switch (qwert) {
> >         case 1 {
> >             yuiop = 3;
> >         }
> >         case 2 {
> >             yuiop = 4;
> >         }
> >         case 3, 4, 5 {
> >             yuiop = 5;
> >         }
> >     }
> >
> > (Note no colons)
> >
> > The idea:
> > - Having the case clauses as block statements seems the logical thing
> > to me.
> >
> > - Declarations/initialisations local to case clauses - I know you can do
> >
> >     case 1: {
> >         Asdfg hjkl = new Asdfg;
> >         // ...
> >     } break;
> >
> > but I still think my idea is neater.
> >
> > - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed.  Maybe an 'else' could be used to override this, e.g.
> >
> >     switch (qwert) {
> >         case 0, 5, 10 {
> >             // do stuff if qwert is 0, 5 or 10
> >         } else case 1..9 {
> >             /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
> >              * (or should this be semi-inclusive like array
> >              * slicing?)
> >              */
> >         }
> >
> >         case 6..13 {
> >             /* do stuff if qwert is 6..13, even if a
> >              * previous case matched
> >              */
> >         }
> >
> >         default {
> >             // this would still mean do stuff if  none match
> >         }
> >     }
> >
> > Nesting could also be allowed, for a bit of syntactic sugar:
> >
> >     switch (qwert) {
> >         case 0..10 {
> >             // do something
> >
> >             case 4 {
> >                 // do something more specific
> >             }
> >
> >             // now do something else
> >         }
> >     }
> >
> > What do you think?
> >
> > Stewart.
> >
>
> Oh no, not switch statements again.  And this was my idea ;)
>
> -- 
> -Anderson: http://badmama.com.au/~anderson/


January 29, 2004
I like that idea.
I would make it an more generic expression instead of an block
then you could write:

switch (qwert)
{
	case 1 foo();

	case 2
	{
		foo2();
	}
}


Stewart Gordon wrote:
> In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
> 
>     switch (qwert) {
>         case 1 {
>             yuiop = 3;
>         }
>         case 2 {
>             yuiop = 4;
>         }
>         case 3, 4, 5 {
>             yuiop = 5;
>         }
>     }
> 
> (Note no colons)
> 
> The idea:
> - Having the case clauses as block statements seems the logical thing to me.
> 
> - Declarations/initialisations local to case clauses - I know you can do
> 
>     case 1: {
>         Asdfg hjkl = new Asdfg;
>         // ...
>     } break;
> 
> but I still think my idea is neater.
> 
> - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter.  Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed.  Maybe an 'else' could be used to override this, e.g.
> 
>     switch (qwert) {
>         case 0, 5, 10 {
>             // do stuff if qwert is 0, 5 or 10
>         } else case 1..9 {
>             /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
>              * (or should this be semi-inclusive like array
>              * slicing?)
>              */
>         }
> 
>         case 6..13 {
>             /* do stuff if qwert is 6..13, even if a
>              * previous case matched
>              */
>         }
> 
>         default {
>             // this would still mean do stuff if  none match
>         }
>     }
> 
> Nesting could also be allowed, for a bit of syntactic sugar:
> 
>     switch (qwert) {
>         case 0..10 {
>             // do something
> 
>             case 4 {
>                 // do something more specific
>             }
> 
>             // now do something else
>         }
>     }
> 
> What do you think?
> 
> Stewart.
> 

January 29, 2004
I think that you've assumed that everyone writes with the egregious K&R bracing, and that your proposal relies on that for digestibility.

"Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:bvb6lc$1t7a$1@digitaldaemon.com...
> In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
>
> switch (qwert) {
> case 1 {
> yuiop = 3;
> }
> case 2 {
> yuiop = 4;
> }
> case 3, 4, 5 {
> yuiop = 5;
> }
> }
>
> (Note no colons)
>
> The idea:
> - Having the case clauses as block statements seems the logical thing to
me.
>
> - Declarations/initialisations local to case clauses - I know you can do
>
> case 1: {
> Asdfg hjkl = new Asdfg;
> // ...
> } break;
>
> but I still think my idea is neater.
>
> - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter.  Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed.  Maybe an 'else' could be used to override this, e.g.
>
> switch (qwert) {
> case 0, 5, 10 {
> // do stuff if qwert is 0, 5 or 10
> } else case 1..9 {
> /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
> * (or should this be semi-inclusive like array
> * slicing?)
> */
> }
>
> case 6..13 {
> /* do stuff if qwert is 6..13, even if a
> * previous case matched
> */
> }
>
> default {
> // this would still mean do stuff if  none match
> }
> }
>
> Nesting could also be allowed, for a bit of syntactic sugar:
>
> switch (qwert) {
> case 0..10 {
> // do something
>
> case 4 {
> // do something more specific
> }
>
> // now do something else
> }
> }
>
> What do you think?
>
> Stewart.
>
> -- 
> My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment.  Please keep replies on the 'group where everyone may benefit.


January 29, 2004
"C" <dont@respond.com> wrote in message news:bvbp1d$2rji$1@digitaldaemon.com...
> Why do people put thier responses at the bottom :P.  All that scrolling makes me dizzy.
>
> C
> "J Anderson" <REMOVEanderson@badmama.com.au> wrote in message
> news:bvb7ip$1umk$2@digitaldaemon.com...
> > Stewart Gordon wrote:
> >
> > > In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
> > >
> > >     switch (qwert) {
> > >         case 1 {
> > >             yuiop = 3;
> > >         }
> > >         case 2 {
> > >             yuiop = 4;
> > >         }
> > >         case 3, 4, 5 {
> > >             yuiop = 5;
> > >         }
> > >     }
> > >
> > > (Note no colons)
> > >
> > > The idea:
> > > - Having the case clauses as block statements seems the logical thing
> > > to me.
> > >
> > > - Declarations/initialisations local to case clauses - I know you can
do
> > >
> > >     case 1: {
> > >         Asdfg hjkl = new Asdfg;
> > >         // ...
> > >     } break;
> > >
> > > but I still think my idea is neater.
> > >
> > > - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed.  Maybe an 'else' could be used to override this, e.g.
> > >
> > >     switch (qwert) {
> > >         case 0, 5, 10 {
> > >             // do stuff if qwert is 0, 5 or 10
> > >         } else case 1..9 {
> > >             /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
> > >              * (or should this be semi-inclusive like array
> > >              * slicing?)
> > >              */
> > >         }
> > >
> > >         case 6..13 {
> > >             /* do stuff if qwert is 6..13, even if a
> > >              * previous case matched
> > >              */
> > >         }
> > >
> > >         default {
> > >             // this would still mean do stuff if  none match
> > >         }
> > >     }
> > >
> > > Nesting could also be allowed, for a bit of syntactic sugar:
> > >
> > >     switch (qwert) {
> > >         case 0..10 {
> > >             // do something
> > >
> > >             case 4 {
> > >                 // do something more specific
> > >             }
> > >
> > >             // now do something else
> > >         }
> > >     }
> > >
> > > What do you think?
> > >
> > > Stewart.
> > >
> >
> > Oh no, not switch statements again.  And this was my idea ;)
> >
> > -- 
> > -Anderson: http://badmama.com.au/~anderson/

I agree!


January 29, 2004
A parsing nightmare, surely!

"Stephan Wienczny" <wienczny@web.de> wrote in message news:bvbtok$2h7$1@digitaldaemon.com...
> I like that idea.
> I would make it an more generic expression instead of an block
> then you could write:
>
> switch (qwert)
> {
> case 1 foo();
>
> case 2
> {
> foo2();
> }
> }
>
>
> Stewart Gordon wrote:
> > In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
> >
> >     switch (qwert) {
> >         case 1 {
> >             yuiop = 3;
> >         }
> >         case 2 {
> >             yuiop = 4;
> >         }
> >         case 3, 4, 5 {
> >             yuiop = 5;
> >         }
> >     }
> >
> > (Note no colons)
> >
> > The idea:
> > - Having the case clauses as block statements seems the logical thing to
> > me.
> >
> > - Declarations/initialisations local to case clauses - I know you can do
> >
> >     case 1: {
> >         Asdfg hjkl = new Asdfg;
> >         // ...
> >     } break;
> >
> > but I still think my idea is neater.
> >
> > - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter.  Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed.  Maybe an 'else' could be used to override this, e.g.
> >
> >     switch (qwert) {
> >         case 0, 5, 10 {
> >             // do stuff if qwert is 0, 5 or 10
> >         } else case 1..9 {
> >             /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
> >              * (or should this be semi-inclusive like array
> >              * slicing?)
> >              */
> >         }
> >
> >         case 6..13 {
> >             /* do stuff if qwert is 6..13, even if a
> >              * previous case matched
> >              */
> >         }
> >
> >         default {
> >             // this would still mean do stuff if  none match
> >         }
> >     }
> >
> > Nesting could also be allowed, for a bit of syntactic sugar:
> >
> >     switch (qwert) {
> >         case 0..10 {
> >             // do something
> >
> >             case 4 {
> >                 // do something more specific
> >             }
> >
> >             // now do something else
> >         }
> >     }
> >
> > What do you think?
> >
> > Stewart.
> >
>


January 29, 2004
Matthew wrote:
> A parsing nightmare, surely!

No, not necessarily. But type ocassionally that extra : as used to from C and you spoil it - thus this syntax is unstable to use. So i'd be against it.

-eye

« First   ‹ Prev
1 2 3