'goto', as an indicator of good language
Dukc
ajieskola at gmail.com
Thu Sep 8 21:30:06 UTC 2022
On Thursday, 8 September 2022 at 21:03:04 UTC, H. S. Teoh wrote:
> The `goto` of today's languages is a much safer, de-fanged
> version of the original goto. In D, for example, you cannot
> `goto` out of a function (or into another). The compiler also
> doesn't let you skip variable initializations / destructions.
> So it's subject to pretty much the same constraints as
> "structured" constructs like if, while, for, switch, etc.,
> except it's more low-level and can do a few more things that
> the other constructs can't do.
Well if I really wanted to I could do it in 60s style by putting
everything inside a giant `switch(callStack.pop)` in `main()`.
"functions" would be just `goto` labels, called like this:
```D
callStack.push(something);
goto function;
case something:
```
...with a jump to the switch at end of each "function" body.
So `goto` does technically have as long fangs as always :D. Of
course, modern languages do a good job encouraging better coding
habits.
More information about the Digitalmars-d
mailing list