Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!mailrus!umix!nancy!eecae!super.upenn.edu!rutgers!pbox!okstate!gregg From: gregg@a.cs.okstate.edu (Gregg Wonderly) Newsgroups: comp.lang.c Subject: Re: The D Programming Language: cases Message-ID: <3278@okstate.UUCP> Date: 8 Mar 88 02:44:59 GMT References: <25200@cca.CCA.COM> Organization: Oklahoma State Univ., Stillwater Lines: 98 From article <25200@cca.CCA.COM>, by g-rh@cca.CCA.COM (Richard Harter): > In article <2403@umd5.umd.edu> chris@trantor.umd.edu (Chris Torek) writes: >>-In article <24996@cca.CCA.COM> g-rh@cca.CCA.COM (Richard Harter) writes: >>-}As a side point, I like the suggestion that someone made that there be >>-}a fallthrough statement rather than automatic fallthrough. > >>While this would work, if we assume D has aggregate constructors, >>there is a handsomer way: > >> switch (e) { >> case [1, 2, 3, 5, 7, 13, 19, 23]: ... >> } >> /* syntax above is only for demonstration */ > > Well, yes, one ought to be able to do that. However it is isn't quite > as strong as fallthrough, where one can say > > switch (e) { > case foo: > some code; > fallthrough; > case baz: > some more code; > } > > > In C as it stands now you can do this -- indeed, the complaint is that > one can do this unintentionally. If one adds aggregate constructors and > takes away automatic fallthrough, it seems to me that you weaken the > language. No doubt there are purists that say you shouldn't do the > sort of thing given above. I wouldn't go that far, but I would agree > that one should be able to use aggregate constructors when cases actually > share code. This is just one of the many things that people gripe and complain about when writing C. In my eyes it comes down to poor/bad (which is your favorite?) program writing practices. You can eliminate the majority of the problems associated with `break' in a switch by prototyping the entire switch before filling in the code (you mean you are coding off the top of your head :-). e.g. switch (val) { case 'a': case 'b': break; case 'c': break; case 'f': case 'h': case 'v': break; default: wrong_again_honey(); } Then you can add the code for each case by opening a line above the `break' statements. If you know that you need a switch, you should know what the structure of it will be initially (prior to adding that other feature), so just type it (you know, like stubbing out a program). While I am at it, one of my biggest gripes is that too many people exploit C's idea of a statement so that they can write if (some_expression) for (init; continuation_condition; repeat_code) switch (val) { forty jillion case's } without placing braces around the `switch' and the `for'. I guess these people either don't use VI, or haven't got a bracket matcher in their favorite editor. This kind of code is terribly difficult to get through. I prefer... if (some_expression) { for (init; continuation_condition; repeat_code) { switch (val) { forty jillion case's } } } Then there are those people who lost sight of their space bar and insist on typing things like, for(a=4,b=5,s=&c;((a>4)+(int)s+1)!=c