|The Trick Of The Mind - Programming & Algorithmic Thought|
|Written by Mike James|
|Friday, 03 September 2021|
Page 3 of 3
Talking of arithmetic and algebra there is one final elaboration we need to make to our little language to make it more like a real programming language and to expand the way we use symbols to describe processes.
If you have a command like FW10 then this is just forward 10 - what do you do if you want to go forward 15 or any any other value?
One solution is to invent another command FW15 but this means you are going to invent a command for every distance you want to use.
Of course the answer is simple.
Don't define the command to be FW10 but define it to be:
where n is any number you care to use that is reasonable. So now in our little language you can write FW 30, FW 15 and so on. We have defined an infinite set of possible commands.
This may seem very obvious to you, but don't underestimate it. We have now moved into allowing commands with a complex structure. Not just Forward 10 but Forward any amount I care to specify.
The n in the definition is a place holder for a value and when you come to use the command you have to replace it by a value that completes the command. In most programming languages n is called a parameter i.e. something that has to be replaced by a value. That is, FW n is not a command that can be carried out, but a template for a family of commands like FW 10.
In the same way, in place of RT90 we can define:
where a is the number of degrees to turn through.
This is where our little language starts to get interesting.
Again if you can't do it in your head try it on a piece of paper.
The answer is a triangle.
Is Programming The Same As Giving Instructions?
Some more philosophy.
So programming is about writing down what to do.
Isn't this the same as simply giving instructions to some one to achieve a goal?
Imagine that we have a drill sergent on the parade ground shouting out orders to a single soldier. Suppose he shouts, foward march, right face, forward march, right face, forward march, right face, forward march. It is clear the result is that the soldier draws a square.
Is the drill sargent programming?
Sort of but not quite.
Programming isn't about giving instructions as they are needed but about writing the whole lot down in some form or another. It is about creating the whole thing not producing the commands as required.
Why is this different?
The reason is that the drill sargent isn't provably planning ahead. He is just reacting to the current state of the system and issuing an appriate command. It might even be that the sargent isn't aware that there is a program at all.
If you create a program you have to think your way into each of the positions that the program entails. You have to know that when the soldier has done FW 10 RT 90 he is at the first corner of the square facing in the direction of the next side. You do not see this fact as physical reality - you have to see it in your minds eye. When you construct a program you get to drill the soldier without needing to put a soldier through any paces at all.
Just as a clock maker assembles as set of cogs and gears to make a clock the programmer puts together instructions which mesh together to create a mechanism. Both the clock mechanism and the program are static when created - neither ticks. The clock maker trusts that the arrangement of cogs will move in the way intended but it is only when the mechanism is started can there be any certainty that this is correct. The programmer similarly gives birth to something static only in this case we need the help of a computer - something that obeys or runs to the program to bring it to life.
A computer is something that obeys a program so converting it from static text to a dynamic mechanism.
The program is like the clock before it is started and the ticking clock is the program when it is being obeyed by a computer.
If you have been following you will now have some idea of what a program is, what a programming language is and what a computer is.
At this stage it all seems trivially easy but I hope you have discovered that our simple drawing language has some difficulties to be mastered/ If you don't appreciate this then try the questions at the end of this chapter.
However, there is the question of what could we possibly need to add to the mix to make a little language into a big language?
A big language is one that you can use to do almost anything. It might lack some facility but this would mostly be a problem with the hardware - e.g. you might not be able to make sounds if the hardware doesn't support it. In principle a big language serves to write any program you can think of.
This sounds like a tall order and it seems to imply something very complicated. While some computer languages have lots and lots of facilities, the truth of the matter is that the simplest big language is much simpler than you might imagine. In understanding what we need to add to our little language, you will discover how to move from its simple type of programming to the programming of everything.
This last question is a slighly crazy example of how programs can go wrong when the programmer's expectations are not the same as the computer's reality.
The Trick Of The Mind - Programming & Algorithmic Thought
or email your comment to: email@example.com
|Last Updated ( Friday, 03 September 2021 )|