June 19, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence rules? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu, el 19 de junio a las 03:15 me escribiste: > On 06/18/2010 10:08 PM, Vladimir Panteleev wrote: > >On Sat, 19 Jun 2010 05:22:47 +0300, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote: > > > >>Walter had no retort to that argument, so he veered into a critique of the goto case XXX solution saying it's unmaintainable: when you moving code around you want to keep on falling through but with goto you'd need to update the goto target. However, it can be argued that logically you want to continue processing at some specific logical point, not to blindly fall through to whatever the heck code happens to be there. > > > >Well, if "goto case XXX" is unmaintainable, how about some combination of existing keywords? For example, "continue switch;". > > > >-- Best regards, > >Vladimir mailto:vladimir@thecybershadow.net > > Clever! Search the archives for the multiple fall-through threads. All have been suggested before. http://www.digitalmars.com/d/archives/154.html#N388 -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- Y Gloria Carrá, Gloria Estephan, Gloria Gaynor y Gloria Trevi. -- Peperino Pómoro | |||
June 19, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Jun 19, 10 17:56, bearophile wrote: > KennyTM~: >> This "fallthrough" statement already exists. >> >> switch (x) { >> case 0: >> do_something(); >> goto case; >> case 1: >> do_more_thing(); >> goto case; >> case 2: >> done(); >> break; >> default: >> error(); >> break; >> } > > I didn't know this, this is a hidden D feature. So it's just a matter of D forbidding the cases that miss an explicit return, goto, or break, assert(0), exit(), and similar. > > As for the multiple returns in a function this needs a bit of care because this is acceptable: > > switch (x) { > case 0: > if (y) > goto case; > else > return x; > default: > break; > } > > Bye, > bearophile Actually it's not hidden :) http://www.digitalmars.com/d/1.0/statement.html#GotoStatement http://www.digitalmars.com/d/2.0/statement.html#GotoStatement | |||
June 20, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence rules? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Don | On 06/19/2010 06:58 AM, Don wrote:
> Andrei Alexandrescu wrote:
>> Don wrote:
>> [snip]
>>> Or is too late to break backwards compatibility with B ?
>>
>> We can and should do it. It won't impact TDPL adversely.
>
> Excellent! I'll make a patch for it when I have time.
Walter just gave the green light, so Don - it's up to you.
He also agreed to give more thought to the restriction of forcing every swich label to be ended with a control flow transfer statement.
Andrei
| |||
June 20, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu: > Walter just gave the green light, so Don - it's up to you. Probably our awesome Don will be able to do it, sooner or later :-) > He also agreed to give more thought to the restriction of forcing every swich label to be ended with a control flow transfer statement. Good :-) Bye, bearophile | |||
June 20, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu: > He also agreed to give more thought to the restriction of forcing every swich label to be ended with a control flow transfer statement. I hope Walter will express his positive vote about this other little C syntax detail, automatic joining of adjacent strings: http://d.puremagic.com/issues/show_bug.cgi?id=3827 Bye, bearophile | |||
June 20, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu Wrote:
> On 06/19/2010 06:58 AM, Don wrote:
> > Andrei Alexandrescu wrote:
> >> Don wrote:
> >> [snip]
> >>> Or is too late to break backwards compatibility with B ?
> >>
> >> We can and should do it. It won't impact TDPL adversely.
> >
> > Excellent! I'll make a patch for it when I have time.
>
> Walter just gave the green light, so Don - it's up to you.
>
> He also agreed to give more thought to the restriction of forcing every swich label to be ended with a control flow transfer statement.
You mean every label that is followed by a statement, correct? This is a common idiom that I wouldn't want to change:
switch (x) {
case 1: case 2: case 3: case 4:
doSomething();
break;
default:
whatever();
}
| |||
June 20, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Sean Kelly:
> You mean every label that is followed by a statement, correct? This is a common idiom that I wouldn't want to change:
>
> switch (x) {
> case 1: case 2: case 3: case 4:
> doSomething();
> break;
> default:
> whatever();
> }
I think he means every case. Sometimes a small change, even if seems a little less handy, is useful. Can't you write code like this, that also looks better to me?
import std.stdio: writeln;
void doSomething() { writeln("doSomething"); }
void whatever() { writeln("whatever"); }
void main() {
int x = 4;
switch (x) {
case 1, 2, 3, 4:
doSomething();
break;
default:
whatever();
break;
}
}
Bye,
bearophile
| |||
June 21, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | bearophile Wrote:
> Sean Kelly:
> > You mean every label that is followed by a statement, correct? This is a common idiom that I wouldn't want to change:
> >
> > switch (x) {
> > case 1: case 2: case 3: case 4:
> > doSomething();
> > break;
> > default:
> > whatever();
> > }
>
> I think he means every case. Sometimes a small change, even if seems a little less handy, is useful. Can't you write code like this, that also looks better to me?
>
> import std.stdio: writeln;
> void doSomething() { writeln("doSomething"); }
> void whatever() { writeln("whatever"); }
> void main() {
> int x = 4;
> switch (x) {
> case 1, 2, 3, 4:
> doSomething();
> break;
> default:
> whatever();
> break;
> }
> }
As long as there's a way to enumerate case labels I don't really care what the syntax is. That would be more than fine with me.
| |||
June 21, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Sean Kelly:
> As long as there's a way to enumerate case labels I don't really care what the syntax is. That would be more than fine with me.
Good (note that the code I have written is already correct D syntax) :-)
Bye,
bearophile
| |||
June 21, 2010 Re: Is there ANY chance we can fix the bitwise operator precedence | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 2010-06-20 19:42:49 -0400, bearophile <bearophileHUGS@lycos.com> said: > I think he means every case. Sometimes a small change, even if seems a little less handy, is useful. Can't you write code like this, that also looks better to me? > > import std.stdio: writeln; > void doSomething() { writeln("doSomething"); } > void whatever() { writeln("whatever"); } > void main() { > int x = 4; > switch (x) { > case 1, 2, 3, 4: > doSomething(); > break; > default: > whatever(); > break; > } > } But what about the "case 1: ... case 10:" syntax? switch (x) { case 1: .. case 10: case 22: .. case 32: case 52, 64: doSomething(); break; default: whatever(); break; } -- Michel Fortin michel.fortin@michelf.com http://michelf.com/ | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply