'goto', as an indicator of good language

Nick Treleaven nick at geany.org
Fri Sep 9 16:31:05 UTC 2022


On Friday, 9 September 2022 at 15:57:45 UTC, Steven Schveighoffer 
wrote:
> 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.

If you know there's no break but there is a continue, you don't 
have to use a label.

> 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.
>

Why would you need to stop reading the code sequentially and 
lookup the closing brace? With goto you need to to understand 
what you're looking at. That's my point.




More information about the Digitalmars-d mailing list