Most algorithms and forms of business logic can fit nicely into the control structures that are built into modern languages, in large measure because such structures were designed to fit the needs of common applications. Some applications, however, need to implement algorithms or business logic that do not fit any such control structures.
Programs are generally most readable if the general design of the program matches the design of the algorithm or business logic implemented thereby. If the algorithm or business logic jumps around in weird bizarre ways, a program which uses goto
to jump around in those same bizarre ways will likely be more understandable than one which has to implement the same logic by adding flags and/or abusing other control structures like switch
/case
.
Most algorithms and forms of business logic will either fit naturally into common control structures, or can easily be adjusted to do so. If the necessary behavior will fit into a language's control structures--as it will for most applications--it's generally better to use those structures than to use goto
. The fact that most programs would receive no benefit from having goto
available, however, does not mean that it does not provide great benefits in cases where the required behavior doesn't fit any other control structure.
Incidentally, another factor to consider with goto
: many languages are used not only to process code which written by humans and intended to be readable by them, but also to process machine-generated code which is not required nor particularly expected to be human readable. If the behavior of the generated code is described by a series of state transitions, it may be much easier for the code generator to define a label for each state and use goto
to hop between them, than for it to try to identify ways of reforming the code to fit the target language's control structures. While some implementations may be better able to process code written using control structures than code written using goto
, many others start by converting all control structures to conditional branches (i.e. goto
) internally and then analyze the resulting control-flow graph. If a compiler is going to turn a for
loop into a bunch of conditional branches, there no reason for a code generator to seek out ways to replace some goto
branches with a for
loop.
goto
is useful because it's easier to map to from code generator operating on the bytecode level. $\endgroup$goto
or (c) asking a computer science question about langauge design in general? It seems to me that you're about 50% a, 25% b and 25% c, which isn't a great mix. I think it would be helpful if you could refactor the question a bit to contain more c and less a and b. $\endgroup$