'goto', as an indicator of good language

Nick Treleaven nick at geany.org
Sat Sep 10 12:41:20 UTC 2022


On Friday, 9 September 2022 at 17:04:44 UTC, Steven Schveighoffer 
wrote:
> So when you say "Not the same", you mean that <1% difference.

That's where bugs hide.

>>>> 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 "}"

Why do I need to stop reading the code sequentially and find the 
closing brace of a switch? I do not. Searching for a label *is 
disruptive*, even if automated, it breaks my train of thought. 
With goto the matching label could be inside the switch or it 
could be outside it, at different levels of scope. With break, 
you know it just jumps to the end of the switch. When I'm reading 
code, I'm trying to understand each statement. I can't understand 
a goto without knowing which scope it goes to. With break you 
know what scope that is. This is a key part of why we have 
structured programming, because you know where the code will go 
to when exiting a construct.


More information about the Digitalmars-d mailing list