Beeflang - open source performance-oriented compiled programming language
Patrick Schluter
Patrick.Schluter at bbox.fr
Fri Jan 10 09:47:57 UTC 2020
On Friday, 10 January 2020 at 09:33:01 UTC, Sebastiaan Koppe
wrote:
> On Friday, 10 January 2020 at 09:00:53 UTC, Patrick Schluter
> wrote:
>> On Thursday, 9 January 2020 at 17:41:31 UTC, jmh530 wrote:
>>> 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);
>> }
>>
>
> or don't do too many things at-once:
>
> void main() {
> auto result() {
> int c = 2;
> if (c == 0)
> return c;
> string op = "+";
> if (op != "+")
> return c;
> int c2 = 3;
> if (c2 == 0)
> return c;
> return c + c2;
> }
> assert(result == 5);
> }
Yes. You can also consolidate
void main() {
int result;
int c = 2;
string op = "+";
int c2 = 3;
if (c != 0 && op == "+" && c2 != 0)
result = c + c2;
assert(result == 5);
}
etc. but that was not the point of my rant.
It was strictly about the "non-looping loop goto obfuscation"
construct.
More information about the Digitalmars-d
mailing list