'goto', as an indicator of good language

Steven Schveighoffer schveiguy at gmail.com
Fri Sep 9 15:57:45 UTC 2022


On 9/9/22 11:40 AM, Nick Treleaven wrote:
> On Friday, 9 September 2022 at 14:22:51 UTC, Steven Schveighoffer wrote:
>>
>> Instead of switch, you can use:
>> ```d
>> do {
>>    ...
>> } while(false);
>> ```
>>
>> And then use a break inside.
> 
> Not the same, continue applies to the do then, not an outer loop. Also 
> not clear until the end of the construct that it's not a loop.

If we are talking about wrapping existing code that might contain a 
continue, you need to also consider that the existing code might contain 
a break. In both cases, you could label the target and use a targeted 
continue or break statement.

But again, goto is better here.

> 
>> But honestly, all this looks like "I want to avoid goto at all costs". 
>> The original looks better to me.
> 
> It's easier to reason about switch because you don't have to read the 
> whole function looking for the matching label.

You don't though. Just search for it. Just like you would have to search 
for the matching closing brace of the switch. At least in the case of 
the label, you can use text search, and not have to account for nested 
braces.

-Steve


More information about the Digitalmars-d mailing list