Named blocks to mitigate removing goto #1372
aswaine
started this conversation in
Suggestions
Replies: 1 comment 1 reply
-
|
Having breakable blocks would be great. I'm not sure about removing |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Probably the most common use of
gotois in error handling: something has gone wrong, jump to the end. The language bakes in three statements which enable different forms of this:continue,break, andreturn. Ifgotoas a statement is not present in the language then this “jump to the end” use case needs to work well.In cpp2, the following is one way to do this:
There are other idioms you could create, but one way or the other it's a surprising idiom.
In other languages such as JavaScript however I can do this, which is more intuitive:
That’s:
do..whileloop be used here when we're not doing any looping?This a generalization of the unified declaration syntax:
to this we add
The “
=” is doing the heavy lifting here: it means that this is a declaration, not something to be invoked now.There's no need for
continueto be permitted to reference such a named block.Secondary observation:
Arguably the presence of this syntax makes it less clear why
nextneeds to exist:next, to control loop variables, is redundant in the newfor.nextstatement can always be appended to the end of the loop.breakstatement, withnextcode following the end of the named block.nextblocks.I don't want to distract from the core suggestion but the opportunity does further suggest that named blocks could be an overall language generalization and simplification.
Beta Was this translation helpful? Give feedback.
All reactions