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

Of course, because it is a legal statement in C/C++.
But you definitely don't need it. And you should not use it in structured programming. That's what students learning C/C++ should be taught: you don't need 'goto'.

I also doubt, that using 'goto' will really speed up any programm. The optimizer of the C/C++ compiler is very powerful.

I think @GolamMostafa is struggling to stay at the level of high-level programming. Always diving deep into the HW level is very counterproductive when talking about high level programming concepts.

1 Like

It seems to me that this task was formulated EXCLUSIVELY in order to justify the increased attention to goto

1 Like

My guess here is that dynamic may refer to dynamic memory allocation...
If memory is dynamically allocated in a code block in a function. Is it de-allocated when you leave the block with a GOTO? A jump instruction will not accomplish that...

1 Like

Is this Jump referring to goto?

goto is part of the jump statements

Jump statements

The jump statements unconditionally transfer flow control.

attr-spec-seq(optional)(since C23) break ; (1)

attr-spec-seq(optional)(since C23) continue ; (2)

attr-spec-seq(optional)(since C23) return expression(optional) ; (3)

attr-spec-seq(optional)(since C23) goto identifier ; (4)

1 Like

goto contiuation > goto > jump

JMP ignores stackframes, goto takes care of stackframes.

Do you think that all learners should be able to implement the following snippet (Fig-1, presented as a Flow Chart) using while-do structure? Practically, they don't. What to do for the failure group? The answer is below from post #16 @westfw.

gotoWhileDo
Figure-1:

The presence of the labels and colons L5:, L6: and L8: just demonstrates that whoever drew this had something in mind as those labels are not required for a flow chart describing at conceptual level the algorithm.

you use a flow chart and then discuss implementation based on the various statements available in the language ➜ here you would discuss the use of a suitable selection statement for the tests and an Iteration statement or Jump statement for the looping.

while (millis() - startTime < 3000) { // 3 sec gone ?
  if (button.onPress()) break; // Was the button pressed ?
}
digitalWrite(led2Pin, LOW); // turn off led2

but you could also do

for (;;) { // or `while (true) {`
  if (millis() - startTime >= 3000) { // Has 3 seconds elapsed?
    break;
  }
  if (button.onPress()) { // Was the button pressed?
    break;
  }
}
digitalWrite(led2Pin, LOW); // turn off led2

and many more variations

you could say "use only the goto jump statement"

L5:
if (millis() - startTime >= 3000) goto L6; // Has 3 seconds elapsed?
if (button.onPress()) goto L6;             // Was the button pressed?
goto L5;                                   // otherwise loop
L6:
digitalWrite(led2Pin, LOW); // Turn off led2
1 Like

His arguments are word salad almost as bad as the spaghetti code scenario he says will occur with lazy goto statements, which is really all he had to say. They make code difficult to follow, unreliable in situations not specifically coded in, difficult to maintain down the road and difficult to build off of.
It is so cumbersome to read articles written this way: just get to the point, man!

1 Like

The problem is, that a flow chart doesn't force you to plan structured programming. If the flow chart already is unstructured, it is difficult to write an according program in a structured manner. But that should be the responsibility of the teacher - to advice the pupils to already plan structured.

The NSD instead of a flow chart forces you to plan structured. Of course you can also plan structured programs with a flow chart - but then its your responsibility. You can plan really ugly spaghetti code with a flow chart.

1 Like

Do you expect that 100% pupil of entry level programming class should be able to convert the given Flow Chart snippet using the above-mentioned while-do structure?

The problem is the given flow chart snippet. How will you teach the pupils structured programming if the given flow chart is already unstructured? The problem are not the pupils.

1 Like

When pupils are at entry level programming class (no programming background at all except the familiarity with Flow Chart symbols) were given the task of presenting the following statement visually, most of them came up with that Flow Chart snippet (Fig-1 post #48).

LED2 will turn Off if 3-sec time has elapsed or Button is opened within that 3-sec window.

What would be the structured form of that Flow Chart snippet? I don't know though I know making State Machine Diagram.

Indeed. I am agree that flow charts are hardly compatible with structured programming.
Why do you need to learn them using the Flow Charts?

2 Likes

Does that mean that the Flow Chart has no role to play in the learning process of Programming Language?

it depends what they learnt and understood before...

I would never dump code in front of students as a first thing...

I would teach the basics of algorithms without any programming language, using students standing on floor tiles in the classroom

and one student tells the "runner" to execute actions with simple orders (step, turn 90° left, shake hand, stop) given a student facing a given direction at start. The mission is to complete a path and go and shake hands with a few fellow students and come back to where they were at started.

someone notes the list of commands

step
step
step
step
turn 90° left
step
step
step
shake hand
turn 90° left
step
step
step
step
turn 90° left
turn 90° left
turn 90° left
step
shake hand
turn 90° left
turn 90° left
step
step
step
step
STOP

and then explain you have built your first algorithm

then introduce repetitions repeat step 4 times or tests repeat step until some condition is true

then introduced named functions (a list of actions with a name) ) for example a student would be trained to execute a few orders and when you call that student name, he steps in the place of the runner, execute the "danse" (the orders) and then the runner takes the place of the "function guy".

etc...

That's the basics of algorithmics (and what Logo was doing or apple has been doing with Swift Playgrounds and tons of other companies).

as you expand the possible tools at your disposal (operators, variables, ...) you can make more complex algorithm.

There are infinite variations on this to do that without a computer at all and make it very engaging and fun (competitions).

you can then explain how to represent this with a flow chart as a visual tool and introduce a coding language to represent these orders.

you can group orders that are similar in "statements" and explain you have various types (start with expression statements, compound statements, selection statements, iteration statements, jump statements) and show how do something while(condition) is different than while(condition) do something

only once they have understood the various statements, the language and grammar and what an algorithm is would I go for the type of question you ask — proposing different ways of coding something.

If you build on sand or on notions that the students did not understand, then for sure they will fail miserably and hate the topic. If you make it fun, engaging, playful, rewarding then you build the next generation of engineers or technicians.

my 2cts.

3 Likes

I can't answer this because I'm not a teacher.
I didn’t find flow charts useful in my training.

1 Like

You being a Chemical Engineer must have seen Flow Chart/Flow Diagram in the Process Control Room of Urea Fertilizer Factory or some other industrial installations.

This is very importatnt to note as it changes dramatically from country-to-country due state's financial contraint to implement the state-of-art Education Policy.

Thanks for taking time to make such a nice post on "Teaching Methodology" which are taught in B.Ed/M.Ed classes; unfortunately, the Faculties of Engineering do not attend such schools and yet they have opportunities to learn it from experienced people.

That brings back memories; including implementations in Pascal.

1 Like