A Conversation for The GOTO Statement
Use them sensibly
Megapode Started conversation Jun 21, 2001
The trouble with programming is that it's a VERY complicated task. I think that most programmers - even very experienced ones - underestimate the complexity of what they do on a daily basis.
Programming techniques that are extolled in the text books and promoted as resulting in code that is more reliable and easier to maintain are, in fact, attempts to compensate for the fact that most or our minds are not really able to comprehend an entire program.
The use of routines breaks programs up into mini-programs. In the classic scheme of things routines do ONE thing, are named meaningfully, and are full of variables that have meaningful names.
The effect of this practice is that we (or rather our tiny minds) can locate the code that takes care of a single, specific task out of the many that most programs must perform, and allow us to focus on that particular task.
Now, rashly deployed GOTOs make life difficult for us (or, if you prefer, our minds) because they lead our attention, our concentration to other, possibly unrelated, parts of the program.
So, to my mind (tiny as it is ), GOTOs that only transfer control WITHIN a subroutine are quite acceptable. Typically what I would use is what I call a "forward" GOTO. That is a GOTO within a routine or loop that transfers control to the exit point of that routine or loop.
"Backward" GOTOs that return control towards the entry point of the routine/loop are more problematic. That's because our minds are used to working from the start of something, towards the end - "down" the code if you like. The backward GOTO makes our minds work in the opposite direction.
Like many things, GOTOs are intrinsically neither good nor bad, rather they can be used wisely or foolishly.
Use them sensibly
Diamond Bert Posted Sep 7, 2001
I agree with Megapode. GOTO is simply a programming verb available in certain computer languages. It's the design and logic of the program that determines whether it's well written or not. The various loops instructions (DO WHILE, DO UNTIL, FOR etc.) together with conditional instructions (IF THEN ELSE, CASE etc.) simply disguise the fact that at some point in the execution of the program control GOES TO somewhere other than the next statement.
As an analogy, I have what I call Survival French. When in France, I can usually make myself understood in shops, bars, restaurants etc. and generally have a great time enjoying myself. However, I recognise that my use of the French language is vastly different from that of Moliere or Voltaire, yet we are using the same language. It's the same with any computer language - it's not what you use but how you use it that makes the difference.
Key: Complain about this post