Skip to content
Snippets Groups Projects
Commit e88701a0 authored by cprutean's avatar cprutean
Browse files

Update file program.ipynb

parent e2d450f7
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:776882d3 tags:
# What is a Computer Program
## What is a Computer ?
Before we start teaching *computer programming* we need to first ask
*what is a computer*. A simplfied structure of a computer is shown
below.
<div>
<img src="png.png" width="500"/>
</div>
The *Central Processing Unit* (CPU) operates on a series of instructions
called a *program* which is stored in *memory*. The CPU consists of an
*Arithmetic Logic Unit* (ALU) which performs such functions as addition,
subtraction, comparison etc. and a *Control Unit* which directs and
monitors the operation of the computer. The *input* and *output* provide
an interface to the outside world, for example the *input* may be the
keyboard and *output* the display screen. The *input* and *output* units
also provide access to data storage devices such as hard discs, DVDs,
USB devices etc. All these may be either connected directly to the
computer or over the *network*.
The computer holds all information (numbers, letters, instructions) in
memory as patterns of binary bits, (ones and zeros). The instructions
are decoded by the *Control Unit* and determine what operations the ALU
performs on the data. The desired sequence of instructions (the
*Program*) have to be placed in memory by the “programmer”, which is
what we will be doing during this course. Remember that the computer is
a machine that exactly follows instructions and it is the sole
responsibility of the programmer to get these instructions right!
The binary instructions used by the computer are not convenient for
humans to use. This is further complicated by the fact that different
computers use different sets of instructions. It is therefore much more
convenient to program in a *High Level Language* which is (more) humanly
readable and is independent of the details of the computer being used.
The high level language chosen for this course is .
From the model above the *program* is a set of instuctions that the
computer hardware implements in strict sequential order.
## What is a program?
### Key Point
The actual program is:
1. written in a *high level language* by the “programmer”, typically as
a text file,
2. converted into low level *machine instuctions*,
3. loaded into memory,
4. executed by the hardware.
so as a *programmer* you see only the *high level language*; all the
rest is handled for you by the *operating system*.
> #### More details
> `Python` is an *interpreted language* which means that the
> *conversion to low level machine instuctions*, *load into memory* all
> occurs automatically *on the fly* as you execute the program, for
> example with the command
>`Python` is an *interpreted language* which means that the
*conversion to low level machine instuctions*, *load into memory* all
occurs automatically *on the fly* as you execute the program, for
example with the command
>```python
python3 MyProgram.py
>```
> from a Terminal Window. You do not have to worry about the underlying
> details, particularly since we are running from Jupyter Notebooks in this course, but an understanding of what is “happening” is useful
> when you are trying to work out why your program is not working….
>from a Terminal Window. You do not have to worry about the underlying
>details, particularly since we are running from Jupyter Notebooks in this course, but an understanding of what is “happening” is useful
>when you are trying to work out why your program is not working….
>In particular when things go wrong, has it failed during
>1. conversion to low level instructions (syntax error),
>2. during load (not able to find libraries or modules),
>3. or execution (did something numerically wrong).
>There are more details on this in [Finding and fixing bugs](bugs.ipynb).
### Key Point
So a *computer program* actually is
1. a set of instructions written in a precisely defined *language* with
a very strict *syntax*,
2. implemented by *hardware* in a strict and precisely defined
sequential order.
and it is the sole responsibility of the *programmer* to get this right.
This is why computer programing is *not easy*.
In this course you have to learn two things at the same time, these
being
1. the syntax of the *language*; *this is mainly covered in the on-line
notes and examples*
2. how to formulate a problem in the required sequential order (program
design); *this is mainly covered in the mini-lectures*. This is
challenging part and a skill you will develop as progress through
this and subsequent courses.
All of this will only start to come together as *you* work through this
course.
> #### (Apparent) similarity with mathematics
When you look at the source for any *computer program* there is an *apparent* similarity with
mathematics. There are *variables*, *functions* and signs; this can lead
novice programmers into a false sense of security…you are NOT *doing
mathematics*, you *are* learning a new language that happens to use the
same symbols!
For example, the usage of ``=`` for assignment (see later) is very different from *equals* and can lead to quite hard to spot bugs.|
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment