'goto', as an indicator of good language

Steven Schveighoffer schveiguy at gmail.com
Fri Sep 9 17:04:44 UTC 2022


On 9/9/22 12:31 PM, Nick Treleaven wrote:
> On Friday, 9 September 2022 at 15:57:45 UTC, Steven Schveighoffer wrote:
>> On 9/9/22 11:40 AM, Nick Treleaven wrote:
>>> 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.

So when you say "Not the same", you mean that <1% difference.

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

If the closing brace is close at hand, then the appropriate label would 
be too. It will even stand out more.

But you are saying "read the whole function". I'm assuming you mean that 
it's far away from the break/goto statement.

If it's off-screen, the label wins hands-down. Using my editor I can 
find "L1:" much easier than I can find a specific "}"

-Steve


More information about the Digitalmars-d mailing list