February 22, 2002 Re: Power switch() | ||||
---|---|---|---|---|
| ||||
Posted in reply to d | "d" <s_nudds@hotmail.com> wrote in message news:a53ql5$2hk1$1@digitaldaemon.com... > Goto should not be used for fallthroughs. Once case enumerations and ranges are supported, the motivation for fallthrough mostly disappears. So, don't worry about it. There won't be any fallthroughs. Visual Basic "select case" semantics imply a break after each case; and yet, in all the Visual Basic code I've read or written (okay, maybe not that much, but still), I've never seen nor coded a fallthrough. I would personally bundle the rest of the reasons for fallthrough behavior under the category of "clever hacks." (Do a web search for "Duff's device", and be prepared to retch uncontrollably.) "Goto" exists in the language to support clever hacks. -- Richard Krehbiel, Arlington, VA, USA rich@kastle.com (work) or krehbiel3@comcast.net (personal) |
February 22, 2002 Re: Power switch() "next" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | Extending the next idea. how about switch(foo) { case 1: {// Some stuff next; // With just a next fall through to the next case } case 2: {// Case 2 code next 4; // With an argument goto the specified case. NB argument must be same type as foo. } case 3: {// Case 3 stuff next 4; } case 4: {// Case 4 stuff. }// implied break } "Pavel Minayev" <evilone@omen.ru> wrote in message news:a55g80$7fq$1@digitaldaemon.com... > "Sean L. Palmer" <spalmer@iname.com> wrote in message news:a552t1$1g0$1@digitaldaemon.com... > > > Someone already suggested "goto case" and "fallthrough". Either one is fine. Just don't use continue or break. > > What about "next"? > > select (foo) > { > case (1) > { > ... > next; // fallthru > } > case (2) > { > ... > next; // fallthru > } > case (3) > { > ... // NO fallthru > } > } > > |
February 22, 2002 Re: so what about switch() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a53n18$2fuj$1@digitaldaemon.com... > "Karl Bochert" <kbochert@ix.netcom.com> wrote in message news:1103_1014316261@bose... > > > Array slicing is the same as case ranges: > > array[2..4] // second, third, and fourth elements > > Arrays are _zero-based_. a[2] is actually the _third_ element. Slicing should be no different! > I think he was talking about the hypothetical case of 1-based arrays. Ofcourse in Pascal you can choose the range of your arrays freely, but it seems people have already chosen. 0-based has also become the standard there (in the VCL at least). > As for the end-inclusive thing... this is a matter of personal taste, I believe. I like it as it is implemented now by Walter. Most people here seem to dislike it though (but have you _tried_ it?)... > > > case [2..4] // cases 2,3,4 > > Could be. Just don't use .. to avoid confusion, some keyword would be better. > I still like: case [2..4) // end-exclusive case [2..3] // end-inclusive. <SNIP> -- Stijn OddesE_XYZ@hotmail.com http://OddesE.cjb.net __________________________________________ Remove _XYZ from my address when replying by mail |
February 22, 2002 Re: Power switch() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Krehbiel | "Richard Krehbiel" <rich@kastle.com> wrote in message news:a55gn1$7nk$1@digitaldaemon.com... > "d" <s_nudds@hotmail.com> wrote in message news:a53ql5$2hk1$1@digitaldaemon.com... > > Goto should not be used for fallthroughs. > > Once case enumerations and ranges are supported, the motivation for fallthrough mostly disappears. So, don't worry about it. There won't be any fallthroughs. > Yes! Agreed! > Visual Basic "select case" semantics imply a break after each case; and yet, > in all the Visual Basic code I've read or written (okay, maybe not that much, but still), I've never seen nor coded a fallthrough. > Pascal also implies a break after each case and it works like a charm. Are there any languages that don't imply a break after a case except for C/C++? What about Java? > I would personally bundle the rest of the reasons for fallthrough behavior under the category of "clever hacks." (Do a web search for "Duff's device", > and be prepared to retch uncontrollably.) "Goto" exists in the language to > support clever hacks. > > -- > Richard Krehbiel, Arlington, VA, USA > rich@kastle.com (work) or krehbiel3@comcast.net (personal) > > -- Stijn OddesE_XYZ@hotmail.com http://OddesE.cjb.net __________________________________________ Remove _XYZ from my address when replying by mail |
February 22, 2002 Re: so what about switch() | ||||
---|---|---|---|---|
| ||||
Posted in reply to OddesE | "OddesE" <OddesE_XYZ@hotmail.com> wrote in message news:a561fa$2vmo$1@digitaldaemon.com... > arrays. Ofcourse in Pascal you can choose the range of your arrays freely, but it seems people have already chosen. 0-based has also become the standard there (in the VCL at least). Yes, also in VB (remember that Collections are indexed starting from 0?), and VB.NET arrays are similar to C ones by default... Funny isn't it? This means that most VB.NET and Delphi programmers will get used to 0-based arrays as well - and then D would be a small island in a large sea... > I still like: > case [2..4) // end-exclusive > case [2..3] // end-inclusive. Me too. The same for slices etc, and everybody's happy. A common math notation, easy to learn and use. |
February 22, 2002 Re: Power switch() "next" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin York | "Martin York" <Martin.York@veritas.com> wrote in message news:a55o6t$bjh$1@digitaldaemon.com... > > Extending the next idea. > > how about > > switch(foo) > { > case 1: > {// Some stuff > next; // With just a next fall through to the > next case > } > case 2: > {// Case 2 code > next 4; // With an argument goto the specified case. > NB argument must be same type as foo. Probably a good idea. The same could be achieved with goto case, but if introduce the new keyword, let's use it to its full. =) |
February 22, 2002 Re: so what about switch() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | Pavel Minayev wrote: > "OddesE" <OddesE_XYZ@hotmail.com> wrote in message > news:a561fa$2vmo$1@digitaldaemon.com... >>I still like: >>case [2..4) // end-exclusive >>case [2..3] // end-inclusive. >> > > Me too. The same for slices etc, and everybody's happy. > A common math notation, easy to learn and use. Not everybody's happy with it, though. I could live with it, but I don't like it -- too hard to see the difference in a small font. -RB |
February 22, 2002 Re: Power switch() | ||||
---|---|---|---|---|
| ||||
Posted in reply to OddesE | "OddesE" <OddesE_XYZ@hotmail.com> wrote in message news:a562qp$5nj$1@digitaldaemon.com... > > Once case enumerations and ranges are supported, the motivation for fallthrough mostly disappears. So, don't worry about it. There won't be > > any fallthroughs. > > > > Yes! Agreed! Me too. Frankly, fallthrough is used so rarely, it won't be hard to mimic it with goto when _really_ needed (and it's even rarer). > Pascal also implies a break after each case and it works like a charm. Are there any languages that don't imply a break after a case except for C/C++? What about Java? Java works in the same manner, AFAIK. C# requires break or return at the end of each case but doesn't insert it automatically (which is stupidity, IMO). However, if case has no body, this requirement doesn't apply and fallthrough happens - this is to support one handler for multiple cases. |
February 22, 2002 Re: so what about switch() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russell Borogove | "Russell Borogove" <kaleja@estarcion.com> wrote in message news:3C768FF8.4030708@estarcion.com... > Not everybody's happy with it, though. I could live > with it, but I don't like it -- too hard to see the > difference in a small font. ...but still better than "always end-exclusive"? =) |
February 22, 2002 Re: so what about switch() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | Pavel Minayev wrote:
> "Russell Borogove" <kaleja@estarcion.com> wrote in message
> news:3C768FF8.4030708@estarcion.com...
>
>
>>Not everybody's happy with it, though. I could live
>>with it, but I don't like it -- too hard to see the
>>difference in a small font.
>>
>
> ...but still better than "always end-exclusive"? =)
Tough call.
I could handle "always end-exclusive" if the array slice
documentation were changed to SCREEAAAAAM about it so that
those who don't intuitively assume end-exclusive have a
fighting chance of learning the rule, and if all examples
of array slice in the documentation have a comment saying
"// remember: end-exclusive, see array slice docs" :)
-RB
|
Copyright © 1999-2021 by the D Language Foundation