The "goto" command (strictly speaking it's a "keyword" and not a "command") first showed up in the original high level languages used on computers. These included Fortran and Cobol. To these were later added PL/1, Basic and many others. The keyword was necessary because it was often the only way to alter the flow of a program so that the program could "make a decision". For example:
IF value > 0 GOTO somewhere_else
do something
GOTO after_somewhere_else
somewhere_ else:
do something else
after_somewhere_else:
carry on doing things
This reflects the way computers actually worked at a low level - and they still work this way. At a low level, computers use instructions such as "jump fred" where "fred" is label attached to a piece of code elsewhere. When the first high level languages were designed it was only natural that this paradigm was carried over.
The major cost associated with a piece of software during its lifetime is not, however, the coding nor even the design. It is usually the testing/debugging and the through-life maintenance with the latter often accounting for over half. Because of this, ease of maintenance became a priority. Code with many "goto"s is not easily maintained - trying to trace the path taken through the code for a particular set of circumstances can be a nightmare. Even worse is trying to alter it without upsetting what happens in a different set of circumstances. This eventually led to the design of languages which had control constructs which did not exist on real computers - they were abstractions. These languages, such as Algol, Ada, C, are referred to as "block-structured". In a block-structured language, a typical (simplified!) way of making a decision is:
IF value > 0
BEGIN
do something
END
ELSE
BEGIN
do something else
END
END IF;
As far as I remember, the first language with a construct of this type was Algol 60 around (surprise, surprise :) 1960. Although Algol still had the "Goto", it's use rapidly became deprecated. Algol was followed by many block structured languages such as PL/1, CORAL 66, JOVIAL, C, Ada and Pascal. Some modern languages have been designed without "goto" - if done correctly, it is always possible to do what could have been done with a "goto" by using other control structures
Another driver of the move away from "goto" is the fact that an optimising compiler can do a much better job (i.e. create more efficient machine code) if there are no "goto"s present in the code. Modern compilers can then also take advantage of the pipelining present in current microprocessor designs so that repetitive operations (program loops) can run more efficiently: the whole loop can be held in the processor's instruction cache.
Learn more about this author, David Harris.
Click here to send this author comments or questions.
Below are the top articles rated and ranked by Helium members on:
by Lam Luu
The discussion of goto command is, undoubtedly, among the most interesting discussion in early software engineering discipline.
Ever since the late 1970s, new programming students have been taught how to use a simple instruction called GOTO, yet are
by David Harris
The "goto" command (strictly speaking it's a "keyword" and not a "command") first showed up in the original high level languages
Add your voice
Know something about History of the 'goto' command?
We want to hear your view.
Write now!
Cast your vote!
Click for your side.
Featured Partner
Society of Professional Journalists
The Society of Professional Journalists is the nation's most broad-based journalism organization, dedicated to encour...more
hide