Search Helium

Home > Computers & Technology > Software > Software & Web Development

History of the 'goto' command

by David Harris

Created on: May 25, 2008

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.

Helium Debate

Cast your vote!

Is Microsoft Office Professional a better software suite than OpenOffice?

Click for your side.

Featured Partner

Freedom Research Institute

more


CONNECT WITH US

Read
our blog
Helum for writers

Write and get published
Share with other writers
Polish your freelancing skills

Join our active writing community
Helium Content Source for Publishers

Quality articles from proven freelancers
Exclusive rights, fast turnaround
Brand engagement, business blogging -- our writers do it all

Get custom content today!

INFORMATION


Helium, Inc.
200 Brickstone Square Andover, MA 01810 USA
#