| The Trick Of The Mind - The Goto Fixed! |
| Written by Mike James | ||||||||
| Wednesday, 24 December 2025 | ||||||||
Page 4 of 4
Proving Turing completeness, i.e. proving that a language can compute anything, is often difficult. In the previous chapter we discovered that you had to prove that the language in question could be used to implement a Universal Turing Machine. With a programming language that has the three forms of flow of control you still need to prove that you can implement a Universal Turing Machine, but usually the ability to use a conditional and a loop are enough to indicate that a language can do the job. Without these forms of control the language is unlikely to be Turing-complete. With them all you really need to prove is that you can implement something that mimics reading a paper tape. NestingPrograms are built using three forms of flow of control – default, conditional and looping, the flow of control atoms. You can put these together one after another as if the flow of control was a model railway set. You can have a loop followed by a conditional, followed by a loop and so on. There is another way of combining the flow of control atoms – you can nest one inside the other. For example, you can have a loop that repeats something that needs a conditional: While condition
instruction
If condition Then instruction
instruction
This makes the flow of control more varied that you might imagine. A particularly common nesting is of loops. You can nest one loop inside another to obtain a repeat of a repeat. For example, if you nest a five times repeat inside a 10 time repeat loop the inner loop will be repeated 10 times making a total of 50 repeats: repeat 10 repeat 5 instruction Why would you want to do this? It is always possible to replace a set of nested loops by a single loop that repeats the same total number of times, but sometimes the logic of the situation is best expressed as a repeat of a repeat. Usually the inner repeat does some job to completion and the outer loop repeats the inner job together with some initialization or processing. For example, if the inner loop is repeat 20 stir coffee the outer loop might be repeat 5 get new cup of coffee repeat 20 stir coffee You can see that the inner loop stirs a single coffee and the outer loop repeats it 5 times to complete the stirring of five coffees. Nesting loops is usually about repeating two actions in this way – getting the coffee five times and stirring each coffee 20 times. Now?It is difficult to put ourselves back in the position of the early programmers trying to do something on a regular basis that was once a rare occupation. The Goto incident is an example of the move away from the way programs are created to a more abstract view. In this case feelings were running high as programmers were being told that the way that they had been programming was very wrong and it was implied that they were damaged beyond recovery by the experience. This may sound extreme, but in many cases it was true. It was difficult to see how obviously correct the Goto-less approach was because the people that needed to be persuaded were unable to see how to program using it. They saw it as an unnecessary straitjacket and confirmation bias made it possible to aggressively reject it. It took a long time for programmers to see the error of their ways and retrain themselves to think in terms of the structured programming primitives. Even today you will still find new questions being asked on forums “What IS so bad about the Goto”, usually with a rider that the questioner wouldn’t dream of using a Goto or that they are asking for a “friend”. Today there really is no dissent from the party line and all of the major programming language support structured Goto-less programming. What is perhaps strange is that many still have instruction labels and a Goto instruction often hidden in the documentation with big warning signs that something terrible will happen to any programmer who dares to use them! Is there a better way than structured programming? Probably not. Summary
The Trick Of The Mind - Programming & ComputationalThoughtBuy Now From Amazon
Chapter List
<ASIN:B09MDL5J1S> To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |
||||||||
| Last Updated ( Wednesday, 24 December 2025 ) |


