'goto', as an indicator of good language

Steven Schveighoffer schveiguy at gmail.com
Thu Sep 8 16:46:38 UTC 2022


On 9/8/22 12:33 PM, 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)
> 

goto in D is sane. You cannot skip initializations. You cannot skip 
variable declarations. You can't jump into other functions. You can't 
jump out of or into certain things (e.g. a finally clause).

Loops and if/switch statements are glorified gotos. If you need 
something different, goto can make code much much easier to 
read/write/understand rather than trying to shoehorn it into one of 
these other constructs.

-Steve


More information about the Digitalmars-d mailing list