Programming


A program is a plan, a set of instructions, today usually meant for a computer :

IN THE BEGINNING - ASSEMBLERS:

Early computers had limited instructions they  could perform and limited resources.
Early computers did not even have buttons like your calculator.
Programs were assembled out of available operations.
If you wanted to add, you connected wires from the number register to the arithmetic unit using a plugboard.

As you can see, this was so clumsy that early procedures soon replaced the wires and switches with words.
You assembled words representing these available operations into an organized program.
This was called assembly language.
Each computer had its own assemblly language codes.
And writing these programs  was called coding.

A simple program might be the same as you pressing buttons on your calculator like this:

         Program for A + B = C

 OPERATION       COMPUTER CODE       CALCULATOR

enter number 1    LOAD loc A     type first number
STORE                            type “+”
enter number 2    LOAD loc B     type second number
ADD               ADD            type “=”

STORE             STORE loc C    type memory store


A BETTER WAY TO DO THIS - COMPILERS:

Assembly language coding was so clumsy and error prone that people wanted to write their programs at a higher, more abstract level insead of each small concrete operation.
So next we wrote programs which looked more like the arithmetic that we could read.
And the computer would convert these programs into the internal computer operations for you.
These programs were called compilers.
Here is a simple example in the popular programming language python;

# convert kilometers to miles

PROGRAM:
factor = 0.621371
kilometers = 5.5
miles = kilometers * factor
print(kilometers, “kilometers equals ", miles, " miles")

OUTPUT:
5.500 kilometers equals 3.418 miles


MORE COMPLEX PROCEDURES - ALGORITHMS:

We soon found that we want to collect useful programs. These beccame libraries.
There are now libraries for math, libraries for searching text, libraries for doing graphic drawings.
 These libraries contain procedures we find useful. We call those algorithms.

One of the most useful algorithms is for sorting.
Suppose I handed you a deck of cards with instructions: sort them.
How would you go about it? There are several different sorting methods. 

Bubble Sort: For example, you might look at your top card and see if the next card goes before or after it. After going throught the deck many times this way, finally all cards move into their right place. This is called a BUBBLE SORT, as the cards keep bubbling up unti all are in place. Unfortunately, this is a very slow method, proportional in speed to the square of the number of items sorted, so we only use it on small numbers of items.

There are better, faster ways to sort the cards.
You might break the deck up into smaller decks, sort them, then merge them.
Or you might take cards and instead of sorting them in place, move them into place in a new deck. 

Here is a fun link to Sorting Algorithm Animations with a simple display.  Watch them race.


NEXT >>>>> Thinking

© Gareth Harris 2019        -         Contact email: GarethHarris@mac.com         -         see also: SentimentalStargazer.com