9,784 views
34 34 votes

An unrestricted use of the "go to" statement is harmful because of which of the following reason (s):

  1. It makes it more difficult to verify programs.
  2. It makes programs more inefficient.
  3. It makes it more difficult to modify existing programs.
  4. It results in the compiler generating longer machine code.

5 Answers

Best answer
48 48 votes
Solution : (A) It makes it more difficult to verify programs.

Proof of correctness : https://en.wikipedia.org/wiki/Goto#Criticism
(1st Paragraph, last 4 lines.)

Option B: goto has no role in making a program inefficient. Adding a "goto" introduces a branch instruction but assuming same program logic this can never be avoided and even when replaced by a proper structural construct like for/while/if -- will still have the branch instruction.

Option C: Actually using "goto" kind of makes it easy to modify an existing program as to make the control flow from say line number 'x' to line number 'y', we can simply do a "goto". This is much harder to do in a proper structural way.

Option D:  This is also false as goto introduces only a single "JUMP" instruction (machine code will be its equivalent; OPCODE for JMP followed by the destination address) and equivalent structural constructs will have longer machine codes. 

• selected by
10 10 votes

Correct Answer everywhere: OPTION A

My Answer: OPTION C

While certainly, Option A is correct one and the sources like https://en.wikipedia.org/wiki/Goto#Criticism are evidence of its correctness. And had Option C be something else, then Option A would have been the default choice.

But, Option C, modifying programs means: ANALYZING + ALTERING the code.

Changing any line of code in a program with UNRESTRICTED NUMBER OF gotos  necessitates fully analyzing whole program again for verification. As might somewhere at the end of the function, there would be a goto targeting the line we have modified.

So, it is just a contest between Option A and Option C. And for me C is more suitable.

Talking about others:

Option B: It makes programs more inefficient.

1. Some programs like DESIGNING STATE MACHINES in c would be much efficient with goto.

2. Multi-level loops could be much efficient with goto then with break,continue and if-elses.

3. Can be optimal too:

In Donald Knuth's Structured Programming with go to Statements, which analyzes many common programming tasks and finds that in some of them GOTO is the optimal language construct to use.(same wiki link)

Option C: It results in the compiler generating longer machine code.

When a goto is converted to ASSEMBLY CODE, just a JMP #address, would be sufficient. Also concrete examples would be:

1. end-of-function garbage collection, where a function has more than one exit points and at each exit point we have to perform garbage collection could be replaced by a goto statement at all these exit points targeting to a place at the end-of-the-function, thus using only one place for garbage collection.

2. Low-level performance improvements

This is only valid in perf-critical code, but goto statements execute very quickly and can give you a boost when moving through a function. This is a double-edged sword, however, because a compiler typically cannot optimize code that contains gotos.

Note that in all these examples, gotos are restricted to the scope of a single function.

(StackOverflow)

3. Reduces Code Size too:

Many Programmers, including Linux Kernel designer and coder Linus Torvalds or software engineer and book author Steve McConnell, also object to Dijkstra's point of view, stating that GOTOs can be a useful language feature, improving program speed, size and code clarity, but only when used in a sensible way by a comparably sensible programmer. (same wiki link)

• edited by
Answer:
Position:
Show:

Related questions

51 51 votes
6 answers 6 answers
13.6k
13.6k views
Misbah Ghaya asked Nov 29, 2016
13,608 views
How many substrings (of all lengths inclusive) can be formed from a character string of length $n$? Assume all characters to be distinct, prove your answer.
33 33 votes
2 answers 2 answers
7.3k
7.3k views
Kathleen asked Oct 4, 2014
7,334 views
An unrestricted use of the "$goto$" statement is harmful becauseit makes it more difficult to verify programsit increases the running time of the programsit increases the...
25 25 votes
3 3 answers
8.1k
8.1k views
Misbah Ghaya asked Nov 27, 2016
8,096 views
Which one of the following statements (s) is/are FALSE?Overlaying is used to run a program, which is longer than the address space of the computer.Optimal binary search t...
7 7 votes
2 2 answers
3.4k
3.4k views
Misbah Ghaya asked Nov 27, 2016
3,362 views
Which of the following statements are FALSE?For poisson distribution, the mean is twice the variance.In queuing theory, if arrivals occur according to poisson distributio...