'goto', as an indicator of good language

max haughton maxhaton at gmail.com
Sat Sep 10 06:27:32 UTC 2022


On Friday, 9 September 2022 at 02:00:28 UTC, Walter Bright wrote:
> On 9/8/2022 5:26 PM, max haughton wrote:
>>> The refactoring can come later in its own PR.
>> It almost never does though, let's be realistic.
>
> Quite a few of my PRs are refactorings.

You are much better than most in this regard but my point is that 
every at some point thinks "This is the million dollar goto, I've 
been waiting for this moment all year" or just that one goto 
couldn't posssibbblyy hurt, and locally they might well be right 
but in my experience with the exception of tight interpreter 
loops I *very* rarely see truly justified uses for goto.

They might look clever but they're usually a symptom of code that 
is to abstraction/design what goto is to structured control flow.

If the code does eventually get refactored then great but 
especially in a professional environment where you might be more 
able to manage a larger refactoring, it's better to pay the 
refactoring cost now rather than later if at all possible.

Another more subtle psychological factor against using goto is 
that sometimes gotos are actually worth it, fair enough, but now 
other people working on the code can see the goto in the corner 
of their eye and think they can program like it's 1999 and blame 
it on the goto.

Replacing gotos with a void function call return is a nice 
pattern that D luckily makes trivial to use, for anyone reading 
unaware of the pattern.


More information about the Digitalmars-d mailing list