Sie sind auf Seite 1von 9

Programming Language

Computer programmers write programs. But as set of instructions that we would understand is
very different from instructions that a computer would understand. To write a program, you have
to use a specific programming language range from the very basic binary system to complex
language with rules and syntax.

Low-level and high-level languages


Programming language is divided into two categories: low-level and high-level. Low-level
programming languages have a very basic form and are often quite difficult for programmers to
use. Different brands of CPU understand different kinds of low-level language, so this type of
language is specific to machine. High-level languages are made for programmers to read and use
easily. Computers do not understand them, so compilers and translators are used to translate
high-level code into machine code. High-level languages can be used on any machine.

Generation of programming language


Programming languages have evolved over the years and have reached their fifth generation.

First generation
First-generation languages are low-level language-machine language or machine code. They
are programming language in their purest form. Machine language can be understood by a
computer, so it does not need to be translated. Binary is used to program in machine language,
Machine language executes very quickly, but it is difficult and time-consuming to write
programs in machine language. Here is an example of code written in binary:
100 0001
100 0010
Recall how chapter 4 used 1s and 0s to solve simple arithmetic problems. Now imagine trying to
use this system to write complex programs. It would be difficult to write them and it would be
easy to makes. That is why later generations of programming language evolved-to make it easier
for programmers to write sophisticated software.

Second generation
Second-generation languages are low-level languages and are often called assembly language.
They use short pieces of code instead of binary. Each code looks and sounds like the value or
action it represents, write programs in assembly language than in machine code. An assembler is
used to translate assembly language into machine code.
This command instructs the computer to add the value 20 to accumulator B:
ADD, 20

Third generation
Third-generation languages are high-level languages. Instead of using machine-specific code,
they use statements in English that are easy for programmers to use. Here are some common
third-generation languages:
Pascal
COBOL (Common Business-Oriented language)
FORTRAN (Formula translation)
BASIC (Beginners all-purpose symbolic instruction code)
C.
And here is a Pascal program that adds two values:
PROGRAM Addition;
VAR
numA, numb, numc : integer;
BEGIN
read(numA);
read(numb);
numC := numA + numb:
write(numC);
END.
The commends are English words that are fairly simple to write and understand. A program
written in third-generation language is easy to follow, because it is structured with statements
and keywords. The BEGIN and END keywords tell you where the processing begins and ends.

Fourth generation
Fourth-generation languages are very similar to third-generation language, except they are even
easier to use. They use English-like statements and offer extra help through, instructions and
wizards. Wizards are program assistants that guide the user. This means that programs can be
written very quickly and easily and may not require the expertise of a programmer. Fourth-
generation languages are often used in business because it is fairly quick and easy to train people
who are not computer experts on how to use them. Here are some fourth-generation languages:
Structured query language (SQL)
Visual Basic
C++
Oracle Report.
SQL is used for managing databases. The following SQL commands tell the computer to
search a collection of data called customer_information for data called cust_name and
select the data if purchases are over 100:

Fifth generation
Fifth-generation language is built on third-and fourth-generation languages. They are sometimes
called non-procedural languages. Require the programmer or user to write out the sequence of
steps to solve a problem. Non-procedural languages only require the programmer to write the
goals that have to be achieved and any constraints or parameters that are required. The computer
solves the problem-it works out the required steps.
For this to work, the computer must have a knowledge base to work, so its problem-solving
abilities are limited to what has already been programmed. This type of language. Here are two
commands in prolog:
?- fruit (apple).
?-fruit(x).
The first asks, is an apple a fruit? The second asks what things are fruits?
The computer could respond:
Yes
x = apple

Implementing a program

Chapter 7 introduced the steps for problem solving. Step 5 was write a program in a
programming language and step 6 was to test and debug the program. Steps 5 and 6 can be taken
together and expressed as five stages that ensure smooth progress:

Stage 1: Create the source code.


Stage 2: Interpret and compile.
Stage 3: Link
Stage 4: Test and execute.
Stage 5: Maintain the program.

Stage 1: Create the source code


Step 1 is when you write the program using a programming language. The code you write using
a high-level language or assembly language is known a source code. Chapter 10 to 12 explains
how to write simple programs using the programming language Pascal.

Stage 2: Interpret and compile


The computer does not understand high-level source code. It requires an interpreter or compiler
to translate the source code into object code, which is a machine language it can understand.
Translators are discussed in chapter 5.

Interpreters translate code one line at a time. Interpreters have to run on the same machine
that runs the program, because the program is interpreted every time it is run. Compilers
translate code in one go and create a stand-alone program. This program can be run on many
different machines, which makes compilers more efficient than interpreters.
If there are errors in a program, it will not translate properly. If there is a syntax error, the
translating and may return an error message.
Stage 3: Link
When you write a long or complex program, you will probably write it in pieces or sections.
Linking puts the sections together to create one piece of code.

Stage 4: Test and execute


Before you run, or execute, a program you should test it on paper to see if it works properly.
Chapter 8 discusses some methods for testing a program. If there are errors in a pro0gram, it will
not run properly.

Stage 5: Maintain the program


Once you have a working program that fulfils its purpose, try to maintain it. Perhaps it needs
some extra features or could be restructured so it is easier to use. Go back to the program code
and modify it. Programmers often keep versions of the programs they write. Each version is
given a number and the programmer will usually write release notes to accompany it. The release
notes explain what is new or different about that version. If there is a new version of an operating
system, such as a new version of windows, application programmers may have to create versions
of their application system.

Testing and debugging


Programs are tested to pick up errors. Three kinds of error can prevent a program from working:
logic errors, syntax errors and run-time errors. Errors can be detected when the program is being
translated, when you check it on paper, and when you execute it. Debugging is the process of
fixing errors when you discover them.

Syntax errors
Code has to be written according to syntax rules, which dictate how you structure statements,
much like the rules of English grammar. A computer cannot understand code when there is a
syntax error. A good indicator that there is a syntax error in a program is when a translator
cannot translate the program properly. An example of incorrect syntax is an IF statement without
an accompanying THEN statement.
Logic errors
Logic errors occur when there is a mistake in the flow or sequence of a program. An example is a
calculation that uses a variable before the user has entered the variable into the program. The
program may run, but the output may be inaccurate. Logic errors can be picked up by doing tests
on paper and creating flowcharts that follow the logical flow of the program.

Run-time errors
Run-time errors occur when the program is being carried out. They may be the result of external
factors, such as lack of computer memory or getting stuck in a loop. Run-time errors can occur
when values lead to illegal operations, such as dividing by zero.

Types of testing
Test your program before you execute it. You can do this in two ways:

Testing on paper and computer testing. Dry-run tests and trace tables are methods of testing
on paper. Dry-run testing is a method of checking that a program does not contain any logic
errors. If the program uses loops, you can use trace table to trace the logic of a program through
multiple values. Both these methods are described and demonstrated in chapter 8.

Computer testing is where you test a program on a computer by running it with as many
different types and combinations of data as possible. In an IT environment, this task would go to
a program tester. The tester runs the program will run in all circumstances and conditions.
For example, if a program requires a user to input numeric data, a tester must ensure that all
kinds of numeric data will work, such as identical numbers, positive and negative numbers, and
values that are when the program is used in a live environment.

Validation and verification


When a program is implemented in real time, it may be free of all kinds of errors and run
perfectly. But a user may enter data that is faulty or invalid and causes the program to run
incorrectly. To avoid this, programmers put data validation and verification checks in the
program.
Validation is where a program checks that the data a person has entered is valid, but it cannot
check the accuracy of the data entered. For example, if a user is required eight-digit password,
the program can check that user has entered eight digits, not more or less. Here are some other
examples of data validation:
Use data ranges to ensure a value falls in a specified range.
Check that the correct format is used, such as a date or time format.
Use a spell checker.
Check that a field has not been left blank.
Check that the correct data type is used, such as numeric values and not symbols.
Verification checks that the data entered is exactly correct. This is a time-consuming process and
tends to be used only when data accuracy is crucial.
Documenting programs
A programmer is not the only person to use a program. Many programs are written by more than
one programmer. A program is not much use to a person if they do not know what it is used for.
Documentation says what a program does and how it is used.

Internal documentation
Internal documentation is also called technical documentation. If you are looking at a long and
complex program that you did not write, internal documentation can help you see how it works.
There are several forms of internal documentation:
A programmer can insert comments into the code. Comments are sentences intended for
the user. They are coded so a computer does not read them. Comments are useful for
explaining a piece of code or are easy to read and do not require many comments.
Indentation groups sets of statements to reveal the structure and flow of a program.
White spaces are spaces in a program created by indentation and by writing statements on
separate lines instead of on one line. White spaces help to make programs clear and easy
to follow.
Identifiers are used for different items of data in a program. Good identifiers clearly
indicate the nature of the data. Chapter 10 has more about identifiers, comments and
program structure.
Programmers may write and update their own technical guides. These guides may have useful
indexes of the mnemonics used in coding plus details of how the program was written. Technical
guides may contain diagrams, flowcharts and algorithms to help explain the program. Other
programmers can refer to technical guides to help them modify and maintain programs.

External documentation
External documentation is often called user documentation or user manuals. User manuals
provide installation instructions, provide instructions and any other technical specifications that a
user needs to run or install a program. Most general-purpose applications have a built-in help
function, which is a digital copy of the user documentation. If you have installed a program on a
computer you may have seen a document called readme or similar in the folder that contains
the program. The readme document has instructions on getting started. Many popular general-
purpose applications, such as word, have instructions built into the program- as you install the
program; a wizard guides you through the steps. When you create a new version of a program
you have written, create new version of the documentation.

Test programs and algorithms for correctness and make required changes

Testing Checking for flaws in program execution.

Debugging debugging is the process of locating and fixing or bypassing bugs (errors) in
computer program code or the engineering of a hardware device. To debug a program or
hardware device is to start with a problem, isolate the source of the problem, and then fix it.

Logic Errors Flaw in program design that causes inaccurate results.


Syntax Errors A set of rules defining the structure of a computer program

Test Run This is when you enter your test data to check if the program is working efficiently.

Test Data Sample data that mimics real data a program will process once it is in production.

Dry-Run A manual transversal of the logic of a program, for example using a trace table to
test the results of a program.

Terms associated with running a program

Source Code This is the typed program instructions that people write, the program is then
translated into machine instructions that the computer can execute.

Object Code In programming, the machine readable instructions created by a compiler from
source code.

Compiler This is a program that converts the entire source code into machine language (object
code) before executing it.

Executing The processor operation that carries out commands; part of the machine cycle
(fetching, decoding and executing).

Interpreter In programming a translator that converts each instruction into machine readable
code and executes it one line at a time. Interpreters are often used for learning and debugging,
due to their slow speed.

Loading This is the process of a computer transferring program instructions from storage to
memory.

Levels of programming languages

Machine Level This is the native binary language consisting of 0s and1s that is recognized and
executed by a computers central processing unit.

Pseudo Code-Algorithms

A pseudo code is an imitation computer program written using mathematical notations and
English like statements to describe the logics to solve a problem or carry out a procedure.
Parts of Pseudo Code Algorithms:

A pseudo code algorithm contains one or more of the following statements.

1. Input Statements
2. Assignment Statements
3. Output Statements
4. Control Statements (sequence input for a program)

Input Statements-: Allow input for a program.

Assignment Statements-: Use to store or change data in a variable.

Output Statement-: Use to control the amount of time a statement or sequence of statement is
carried out based on some conditions.

The Input Statement

Variable-: A named location in memory the value of which may change during the execution of
a program.
Constant-: This provides location for storing data which do not change during the execution of a
program.

Identifier-: An identifier can be the name of a variable or a constant.

The input statement is used to get data from outside the computer via some input device into a
variable for manipulation by the pseudo code. For input will use Read. We will use the
following conversion.

Example 1

Write a pseudo code algorithm to read values into variables A and B.

Read A, B
Or
Read A
Read B
Example 2
Write a pseudo code algorithm to values into variables Month, Years, Date.

Read Month, Years, Date


Or
Read Month
Read Years
Read Date

Assignments Statements

Assignment statements are used to give initial value to variables and to change the value assign
to a variable. The assignment statement has two parts:

1. The L Value
2. The R Value

The L value refers to variable as the storage location where the R value will be stored.

The R value refers to value which may be the result of an expression or the content of another
variable.

Write an assignment statement to store the value 2000

Salary = 2000

Write a pseudo code algorithm to read two numbers and find their sum

Read num 1
Read num 2
Sum = num1 + num2

Das könnte Ihnen auch gefallen