'goto', as an indicator of good language

Dukc ajieskola at gmail.com
Thu Sep 8 20:39:30 UTC 2022


On Thursday, 8 September 2022 at 16:33:58 UTC, AnimusPEXUS wrote:
> There was a discussion sometime ago in a Russian Dlang Telegram 
> chat about 'goto' keyword. And there was some empiric theory, 
> stating 'all good languages support goto statement'. Nor Rust, 
> nor Carbon, nor Zig will never going to overcome D or C++ 
> because of this. Language should give possibilities, not take 
> them away. And in some cases, goto able to make code more 
> readable, more sane and more understandable. Also, goto is much 
> safer in language with GC.
>
> [corresponding section in 
> wikipedia](https://en.wikipedia.org/wiki/Goto#Criticism)

My personal attitude to `goto` is that it's overhated. While it's 
true that conditional and loop statements are mostly better, an 
occasional `goto` is not necessarily a code smell. Also I'd be 
much more worried about mutable `static`/global variables and 
oversized functions/types than a few needless `goto`s in a module.

I suspect it's bad reputation is from the times when some 
(non-assembly) languages did not have structured programming and 
everything was done with `goto`s. Going back to that sure would 
suck, but there's quite a difference between an occasional `goto` 
and replacing all your loops with it.

That said, I don't often find use for it. In C# and C++ I 
sometimes prefer it, but when I resort to it in D I usually 
notice a better way shortly afterwards. I'd be slightly annoyed 
to live without it but could easily cope.


More information about the Digitalmars-d mailing list