C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Bringing break/continue with label to C++

From: Tiago Freire <tmiguelf_at_[hidden]>
Date: Tue, 7 Jan 2025 06:44:03 +0000
> Frederick wrote: Are you sure we even need 'goto' anymore? Even at runtime?

Yes, I have written a couple myself. Most often in the context of parsing where special tokens would cause a skip of a procedure.
Where typically you have to do A B and C in order.
A is a loop, but if a special token is hit what you need to do is not only to break out of A but to skip B entirely and go straight to C.
Attempts at re-writing this pattern in terms of functions/alternative code flows/special states has always resulted in worst code and much more spaghetti.
A goto in this case prevents the spaghetti instead of causing it, it is the best tool for the job as it does exactly what you want and prevents the need to track extra state.

Just because you have never used it, it doesn't mean it doesn't have a use.
Yes, its usage is very rare, I've probably written a goto only 4 times in the past 11 years.

But we are missing the mark here. Discussing how useful it is is completely missing the mark, you are not seeing the bigger picture.

It's completely irrelevant that it is the most useless control flow statement in today's programming.

The problem is that:
* It exists
* It has a lexical meaning
* It ain't going away.


> Hyman Rosen wrote: Back in my ancient programming days, I would start ed and go
> g/goto/p
> and I would know all the labels that were the targets of gotos.
> I doubt that this task has gotten significantly harder since.

I agree, given the amount of times you would need this, once in a blue moon, you can solve this problem manually even in extremely large codebases.

The problem is to keep the code clean.
It is the same reason why you would want to make variables const by default, it is the same reason why you would want to define variables in the narrowest possible scope you could possibly use it for, or why you wouldn't use globals everywhere.
It's because we don't want things that you don't need from outstaying their welcome. A label is a thing that outstays long after they are no longer welcome.
It's probably fine, but do I need to keep constantly looking at my shoulder to see if that label is going to stab me in the back?
Let me forget things that I no longer need, and keep things clean.

Received on 2025-01-07 06:44:08