Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SciProg2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pclark3
SciProg2024
Commits
e88701a0
Commit
e88701a0
authored
5 months ago
by
cprutean
Browse files
Options
Downloads
Patches
Plain Diff
Update file program.ipynb
parent
e2d450f7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CourseNotes/program.ipynb
+7
-7
7 additions, 7 deletions
CourseNotes/program.ipynb
with
7 additions
and
7 deletions
CourseNotes/program.ipynb
+
7
−
7
View file @
e88701a0
...
...
@@ -65,16 +65,16 @@
"rest is handled for you by the *operating system*.\n",
"\n",
"> #### More details \n",
">
`Python` is an *interpreted language* which means that the\n",
"
>
*conversion to low level machine instuctions*, *load into memory* all\n",
"
>
occurs automatically *on the fly* as you execute the program, for\n",
"
>
example with the command\n",
">`Python` is an *interpreted language* which means that the\n",
" *conversion to low level machine instuctions*, *load into memory* all\n",
" occurs automatically *on the fly* as you execute the program, for\n",
" example with the command\n",
">```python\n",
" python3 MyProgram.py\n",
">```\n",
">
from a Terminal Window. You do not have to worry about the underlying\n",
">
details, particularly since we are running from Jupyter Notebooks in this course, but an understanding of what is “happening” is useful\n",
">
when you are trying to work out why your program is not working….\n",
">from a Terminal Window. You do not have to worry about the underlying\n",
">details, particularly since we are running from Jupyter Notebooks in this course, but an understanding of what is “happening” is useful\n",
">when you are trying to work out why your program is not working….\n",
"\n",
">In particular when things go wrong, has it failed during\n",
">1. conversion to low level instructions (syntax error),\n",
...
...
%% 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.|
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment