(Latest Revision: 01/30/2012)
CS 1500 Week One Lesson
Introduction to Computer Systems
Here we have a graphic depicting a computer system.
The purpose of any language is the expression of ideas.
In the case of a computer programming language, the only ideas that need
expression are actions to be performed by a computing system like the one
depicted in the diagram.
What actions are such systems capable of?
A lot of what computers can do centers around "storage" - which is also
referred to as "memory." In order to get work done, the computing system
needs to "move data around". In other words, data needs to be copied from one
storage location to another. Thus computer languages need to express commands
to
- copy data from the keyboard to the RAM,
- copy data from one location in RAM to another location in RAM,
- copy between the RAM and the secondary memory (disk), and
- copy from RAM to the computer screen.
The CPU of the computer can perform simple operations on data. Therefore
computer languages need to express commands that tell CPU's to
- copy data from place to place
- perform a specific operation (like add, subtract, multiply, divide)
- report the outcome of the operation, and
- make a simple decision regarding which instruction to execute next (this
why it's possible to have if-then logic in programs, loops, and sub-programs.)
Normally, the Operating System provides the "face" of the computer that the
user sees. The OS is a virtual computer - it simulates a computer that is
more convenient to use than the real hardware.
What is programming?
- A programmer designs a program.
- The programmer uses an editor (like notepad, texteditor, xcode or jove)
to write the algorithm in a high level language such as C++.
- The programmer or user executes a compiler to translate the high level
program (source code) into a machine language program (object code) that
the computer is able to execute.
- A person who wishes to use the program executes the machine language
version of the program.
- There's a variation of this paradigm that involves 'interpretation' - in
some programming environments, the user executes an interpreter program
with the high-level language as an input. The interpreter translates the
program one statement at a time, and executes the machine language
translation of each line immediately after translating it. The paradigm
in our class will be to use a compiler, not an interpreter.
When editing there is an interplay between the primary and secondary memories.
- The goal of the programmer is to use the editor to create a file on
SECONDARY memory - a file that contains the source code of the program.
- However, while editing, the programmer actually makes changes to a
(volatile) COPY of the file. The COPY resides in the primary memory.
After s/he makes updates with the editor, the programmer has to perform a
SAVE OPERATION in order to copy the updates to the permanent copy of the
file in secondary memory.
Word processors are great for creating many kinds of documents but they are
absolutely the WRONG tool for creating a program - because compilers can't
understand anything but 'plain text'.
Programming is basically just problem solving. The challenging part is to
figure out the steps required to solve the problem - the algorithm.
Once we have an algorithm, it's pretty easy to figure out how to write a
program that performs the steps. Of course, there IS a learning curve to
getting good at THAT part of the process too.
In an algorithm, ORDER is EXTREMELY important. You have to specify what is
done first. second, third and so on. If something is done out of order, it
can ruin the entire outcome of the program.
Quoting from our text: "To qualify as an algorithm, a set of instructions must
completely and unambiguously specify the steps to be taken and the order in
which they are taken."
Steps in program design
- Specify: What EXACTLY do we want this program to do?
- Figure out an algorithm that satisfies the specs.
- Check/Test the algorithm
- Write the program in a high level language
- Test the program.
The process described above is often not as 'linear' as described. Often one
has to back up and re-do steps - for example when testing reveals errors.
A mistake or error in a program may be called a bug. The three main types of bugs are:
- Syntax Error (bad syntax - e.g. bad C++ grammar) An example of a syntax
error in English would be a spelling error like spelling climate
"klaimutt", or incorrect part of speech: "He are my friend."
- Logical Error (incorrect meaning - like saying "Go left" when really you
meant "Go right")
- Runtime Error (Something that may turn out to be illogical, but it can't
be known until the program actually executes - like instructions that say
"first read the numbers X and Y from the keyboard input, then divide Y by
X" -- but then when the program reads X, X=0 and the operation Y/X can't
be performed.)
Compilers will catch syntax errors and print error messages (which are
typically hard to understand). The programmer (and helpers) are usually stuck
with the job of finding logical and runtime errors. However, compilers may
print "warnings" that help programmers discover logical or runtime errors.