This was the basic discovery of the 1960s revolution in programming – structured programming – where the confusion of the previous decades was swept aside by simplicity.
Structured programming introduced a Spartan ethic to programming that attempted to change messy complex programs that used all sorts of conditional and loop constructs into easy-to-read texts that used one conditional and perhaps one or two other types of loop.
It is surprising from today’s perspective that something as simple as restricting the range of instructions that programmers used could have been thought of as revolutionary and the solution to the problem of creating better programs!
The fact that it was revolutionary is more an indication of how primitive our approach to programming had previously been.
The computer had to be invented and people like Johnny Von Neumann wrote mathematically elegant theories of how they should be built. Programming, on the other hand, wasn’t invented it just happened! It took some time for it to be realised that we needed a theory of programming – we still do.
We can look back on the “structured programming” era with mixed feelings.
It was a time when programmers were given a set of fairly arbitrary rules and told that this was the only way to program properly.
Today we know that there are many ways of writing a good program and what is more important is to realize that a good program is a program that is easy to understand. It isn’t only the computer that has to read and obey the program but other programmers who have to read it and understand it if they are to have any hope of fixing and extending it. This idea, that programs have to be designed to be obeyed by computers and read by humans, is probably the single most important step forward in programming theory to date! Yes even more than objects or functional programming.
Real programming languages generally have a range of different types of loop construct, just to make programming easier. For example, Visual Basic has
DO WHILE condition Actions to be repeated LOOP
DO Actions to be repeated LOOP UNTIL condition
In fact many modern languages have taken the loop construct and set it free.
The only way that loops differ is in where their “exit” point – i.e. the instruction that stops the loop – is placed. A WHILE loop has its exit point at the very start of the loop and a REPEAT loop has its exit point at the very end of the loop. In Visual Basic and many other languages you can have both of these and you can have an exit point anywhere within the loop
DO Actions to be repeated 1 IF condition THEN EXIT DO Actions to be repeated 2 LOOP
Now the list of actions before the exit will be carried out at least once, but the list after the exit might not be carried out at all – a sort of cross between the WHILE and the UNTIL.
Back in the dark days of structured programming such a construct would have been heresy but now we know better and are more broad minded…
Programming is all about translating a static text of instructions into a set of actions that occur in a particular sequence.
It is the mapping of the text to the sequence that is the essence of programming.
What has modular arithmetic got to do with the real world? The answer any experienced programmer should give you is "a lot". Not only is it the basis for many an algorithm, it is part of the hardware. [ ... ]
This xkcd cartoon provides an ideal excuse to explain Kolmogorov complexity. It is an interesting topic and one that gets right to the heart of programming of how programming relates to ideas like inf [ ... ]