Understanding the harmfulness of goto statement referring to Edsger Dijkstra's Journal Paper of ACM-1968

This is our veteran Forum Member @alto777 who has kindly quoted the above-mentioned Journal Paper of ACM-1968 on the harmfulness of goto statement in this thread.

I have gone through the paper few times, and naturally it has not been possible for me to uderstand many of the concepts of the paper written by a distingished Computer Scientist and Software Developer, Edsger Dijkstra -- a name that I came across in my Masters class some 33 years ago.

First of all, before I put what I have not understood properly in this journal paper, I wish to hear from the Forum Members why the C++ Languge Specifications still do contain goto statement though Edsger Dijkstra asked for its abandonment in the referred paper some 56 years ago?

1 Like

One reason that I can think of is backward compatibility. Imagine a piece of code of thousands or millions of lines of code riddled with goto statements. If it needs a minor rewrite, you don't want to start rewriting the complete code because of the goto statements that are no longer supported.

5 Likes

This hardly means that there is anything wrong with the article. As we saw in a recent discussion about timers, you can’t always understand the datasheet after ten readings :slight_smile:

Do you not agree with Dijkstra's arguments?

PS I read the article (in shorted translation) at the beginning of my programming lessons about 30 years ago .
I have never used goto in my programs (not even once in 30 years). For me, this operator simply does not exist in C++.

A student of Electrical and Electronic Engineering and then have earned a Masters in CSE and then have spent professional life for 16 years in fixing Top Class Proprietary Logging Instruments of Electrical/Electronic nature and then have spent 29 years in teaching and building MPU/MCU based systems, how can you expect from such a student with a very low level knowledge and skill in the Fundamentals of Computer Science (NOT Computer Engineering) be grasping the vision of a highly fertile Computer Mind of Edsger Dijkstra so easily?

As you have read the referred paper, please paraphrase the following paragraph (with examples) quoted from that paper.

Have you taught Programming Language course? If yes, then you must have experience in knowing why goto is a powerful tool to motivate the entry level students to grasp the concept of while-do structure which implicitly contains goto statement.

Is goto an operator or statement?

There was a time when if and goto and line numbers was all I had. I had BASIC, but I had no book.

I haven't used it in forever and just a few days ago I was writing a PR for the IRQManager in the R4 core and ran across one that was used as a bailout in a super long function. I ended up continuing its use in my additions just to maintain their pattern. Although a simple return true would have done as much.

2 Likes

Not much. I graduated in Chemistry Engineering and Programming was a side subject for us. Every that I know I have learned by books.

I see, the while is not the one that contains goto impliciltly... The switch-case is another classical example. Of course, I used them in the code. What I meant - that I avoid (successfully) using goto explicitly.

1 Like

Now, you are inline to discuss the subject matter. This is a 1968 paper when I was just 13. It is an opportunity for us due to @alto777 to see why and how the presentation of the goto statment can be avoided in the class room for entry level pupil as well as in programming.

I am referring you to this thread to assess why I have presented the goto-based sketch (Step-3 post #18) to the OP at the first place rather than presetnting the goto-free sketch (Step-4 post #18).

I learnt C/C++ with help from 2 friends and online tutorials, and later this forum. Previously I was self taught in Z80 and PIC assembly language. I had no idea C/C++ had goto until a previous discussion on here about it. I think my first reaction was to think there was a mistake as I didn't believe C/C++ had goto. I can't imagine any possible reason to use it, and it seems to me that using it would quickly make a mess of the structure that using functions naturally imposes.

Interesting discussion though.

As for the paragraph quoted in reply 4 it looks like a lot of fancy words to say nothing.

3 Likes

As you said in that discussion, you wrote the goto-based sketch because it's faster for you.
It's strange to hear such an argument from a person who is graduated in programming. It seems to be a bad habit, as for me.
I always write straight away without Goto and I don’t think it’s slower.

1 Like

Not really. Here this paragraph is taken out of context, but in general it simply complements the main idea of the article - that the goto operator hides the connections between individual parts of the program and makes understanding the code structure less clear.

1 Like

Ok! I agree if I would be writing that program for myself.

I have written that for the OP who is a Car Mechanic (according to him) without any programming background.

Nobody has objected on the Flow Chart of that thread; but, they have objected on the goto-based codes without noticing that I have converted the Flow Chart into programming codes label-by-label for easy understanding of OP. In Step-4 of post #18, i have presented the goto-free sketch.

I completely understand this argument... although I probably wouldn't use goto anyway. And especially because it is intended for a beginner - so as not to instill bad habits in him from the very beginning.

Thank you.

Your explanation makes sense, thank you. It does not change my opinion on the paragraph though.

To me, that paragraph is sovereign in its content. It can be read and understood without making any reference to any other Section of the paper to which it belongs.

The paragraph is a preample of the paper and talks about the inherent limitation of the human mind which tends to reamin glued with static affairs like believing that the earth was an stationary object until Aristarchus had said the opposite in the third century BC. (The theme of the para is a motivating tonic for the programmers to change their habits/minds not to using goto statement in programming.)

How many of the Arduino Programmers realize that this command: digitalWrite() written in pure static text is converted into a series of timing functions (a dynamic process) by the Sequence Generator of the MCU to achive a result?

GOTO as a concept is fine, especially for teaching how the more "structured" features work.

To understand why GOTO is a bad idea in practice, you probably have to have worked with a language (say, early BASIC or ForTran) that didn't HAVE the more modern features. and seen how easily programs become unreadable.

2 Likes

It is a very interesting.
What kind of dynamic process you see in the simple writing a bit to the GPIO output register?

When about 50 students of an entry level programming class were asked to write multi-line codes for the following structure, about 95% of the pupil failed to answer. The reasons, as discovererd, is that the failure group was not familiar with goto statement.

When the above affair was reported to the Head of the Department, the Head immediately recommended the concerned Teacher to teach the students the goto statement.

while(digitalRead(Button) == LOW)
{
    ; //wait
} 

==>
L1: int buttonStatus = digitalRead(Button);
if(buttonStatus == LOW)
{
    goto L1;
}

This is the complete digitalWrite function for AVR:

void digitalWrite(uint8_t pin, uint8_t val)
{
	uint8_t timer = digitalPinToTimer(pin);
	uint8_t bit = digitalPinToBitMask(pin);
	uint8_t port = digitalPinToPort(pin);
	volatile uint8_t *out;

	if (port == NOT_A_PIN) return;

	// If the pin that support PWM output, we need to turn it off
	// before doing a digital write.
	if (timer != NOT_ON_TIMER) turnOffPWM(timer);

	out = portOutputRegister(port);

	uint8_t oldSREG = SREG;
	cli();

	if (val == LOW) {
		*out &= ~bit;
	} else {
		*out |= bit;
	}

	SREG = oldSREG;
}

Where do you see timing functions and any dynamic process???

1 Like

I'm watching this with interest, but one thing seems to be missing: What is meant by 'dynamic' or 'dynamic process'? From my point of view any process is, by its nature, dynamic. If it were not then nothing would happen. So, what, in this context, does 'dynamic process' mean?

3 Likes