The Trick Of The Mind - Programming & Algorithmic Thought
Written by Mike James
Friday, 03 September 2021
Article Index
The Trick Of The Mind - Programming & Algorithmic Thought
Following Instructions
Is Programming The Same As Giving Instructions?

## Parameters

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:

FW n

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:

RT a

where a is the number of degrees to turn through.

This is where our little language starts to get interesting.

What does:

`FW 100RT 120FW 100RT 120FW 100`

draw?

Again if you can't do it in your head try it on a piece of paper.

## 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.

## What Remains?

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.

## Questions

1. Write a program to draw a  hexagon. Make sure the program ends on an FW n instruction.

2. What happens if you run the program in 1 six times without erasing the previous drawing?

3. Can you modify the program so that you just get one hexagon no matter how many times it is run?

4. Why does this make a difference and is there a general principle here?

5. Finally a trick but fun question. You give me the program that draws a square and I run it but I report back to you that I am back where I started after the first three FW instructions.
Where am I?

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.

## Summary

• Language can be descriptive but it can also be prescriptive.

• A list of instructions is a static version of a process that can be activated by a computer that obeys the instructions.

• Little languages capture very specific types of process such as simple drawing operations.

• An example of a complex little language is the language of arithmetic expressions - a particularly difficult language because the order in which things have to be done doesn't correspond to the order in which they are written.

• The form of instructions can be complex - for example you can have instructions that use parameters to specify exactly what happens.

• A programmer doesn't just issue instructions as they are needed, but puts them together to build a complete process which is a symbolic representation of the process that can be activated by running it on a computer.

#### Related Articles

Grammar and Torture

The Computer - What's The Big Idea?

The Essence Of Programming

## The Trick Of The Mind - Programming & Algorithmic Thought

Contents

1. Description, prescription and little languages.
2. Big languages - Turing complete, loops and conditions.
3. The Flow Of Control and the Control of Flow
4. Breaking it down - modules, subroutines, procedures
5. Data And Algorithms
6. Fundamental Algorithms We All Should Know
7. Divide and Conquer - When Algorithms seem like magic
8. The Hall Of Mirrors - Recursion and Madness
9. Objects
10. Programming As Math

 Flutter Improves Performance14/09/2021There's an updated version of Flutter with improvements including performance and feature improvements to help users track down performance problems in their own apps, full screen support for Android, [ ... ] + Full Story Intel Ditches RealSense 23/08/2021Intel has taken the decision to "wind down" its RealSense vision division. As well as signalling the end of its range of the high-tech cameras and sensors, this also means the end of the road for Inte [ ... ] + Full Story More News