Beeflang - open source performance-oriented compiled programming language

Patrick Schluter Patrick.Schluter at bbox.fr
Fri Jan 10 09:00:53 UTC 2020


On Thursday, 9 January 2020 at 17:41:31 UTC, jmh530 wrote:
> On Thursday, 9 January 2020 at 17:19:38 UTC, Gregor Mückl wrote:
>> [snip]
>>
>> do {} has a separate meaning in beef. These blocks are not 
>> looping, but using break; is valid in them to skip to their 
>> end. While this is certainly creative, I don't know if it all 
>> that useful. But it burns the "do" keyword in the grammar and 
>> something else is required to start a do/while block.
>
> I think his point is that do {} while(false) is basically a 
> non-looping do statement. So you can use breaks within it like 
> below (adapting the example from beeflang.org). The only 
> difference I can see is that you can return from Beef's do 
> statement. There's probably a way to do that in D, but I 
> haven't thought a lot about it.
>
> void main() {
>     int result;
>     do {
>         int c = 2;
>         if (c == 0)
>             break;
>         string op = "+";
>         if (op != "+")
>             break;
>         int c2 = 3;
>         if (c2 == 0)
>             break;
>         result = c + c2;
>     } while (false);
>     assert(result == 5);
> }

Use goto, then people will know that these breaks are gotos in 
disguise and the code is more readable (less indentation, no 
confusion with a loop, no catastrophic nesting where you don't 
know where the break go to) and is much simpler to modify.

void main() {
     int result;
     int c = 2;
     if (c == 0)
       goto skip;
     string op = "+";
     if (op != "+")
       goto skip;
     int c2 = 3;
     if (c2 == 0)
       goto skip;
     result = c + c2;
skip:
     assert(result == 5);
}


Never use the do {} while(false) construct, it's stupid. Burn it 
with fire.

PS: yes, I'm passionate about that construct; it poisoned our 
code base because of a colleague who used it all the time. It is 
a real pain to get rid of it (of course they were not used in a 
10 line example, but in 300/400 lines nested behemoths).


More information about the Digitalmars-d mailing list