The D Programming Language: goto

Karl Heuer karl at haddock.ISC.COM
Wed Mar 9 03:41:16 AEST 1988


In article <25350 at cca.CCA.COM> g-rh at CCA.CCA.COM.UUCP (Richard Harter) writes:
>Yes, there are rare occasions where a goto lets you build by hand a construct
>that is not available in the language.  Most of these instances reflect
>deficiencies in the language.

There are only three reasons for using a goto.  Firstly, to implement a
control structure not directly available in the language in question.  This
"deficiency" is not necessarily bad; I've used goto to emulate coroutines, but
I probably wouldn't want to see coroutines added to the language.  If you
remove goto but then add every other possible flow construct just to avoid the
desire for a goto, you end up with BLISS.  Let's not do that.

Secondly, error handling, which could be considered a special case of the
first reason in that it emulates an exception construct of some type.  This
includes not only cleanup-and-return but also retry-operation; sometimes a
simple backward goto is clearer than a while.

Thirdly, you can use a goto if you really, really want to, a whole lot.  :-)
(I use this as my universal escape clause.)

>The question I was raising was whether the rare instances where a goto
>is actually useful warrant retaining it in the language.

I think so.  When you do need it, it's a pain to emulate.

Also, it would be nice if D source could be automatically generated from C
source.  Retaining the goto makes this easier.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list