Programming


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

IN THE BEGINNING - ASSEMBLERS:

Each computer had a limited set of instructions it  could perform and a limited set of resources it could use.
Early computers did not even have buttons like your calculator.
If you wanted to add, for example, you connected wires from the number register to the arithmetic unit using a plugboard.
These early computers only 
had a few registers which could hold numbers to perform arithmetic, like the display on your calculator. And they only had a small memory, locations where we could store numbers. 

And could do only a few simple operations, such as:
         load registers from memory, store registers into memory, add to register, subtract from register, etc.

As you can see, this was so clumsy that one of the first early programs replaced the wires and switches with words.
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

INSTRUCTION      COMPUTER       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 still so clumsy and error prone that people wanted to write their programs at a higher level. So next computers got so big and fast that we could write programs which looked more like the arithmetic that we could read and the computer would convert these expressions into the internal computer program for you. These programs were called compilers. Here is a simple example in the popular programming language python;

# convert kilometers to miles

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 find that we want to collect useful programs. These we call libraries. There are libraries for math, libraries for searching for words, 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 he 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 to the square of the number of items sorted, so we only use it on small numbers of items.

There are other ways to sort the cards. You might break the deck up into smaller decks, sort them, the 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