Characteristics of a Good Programming Language:

Download Report

Transcript Characteristics of a Good Programming Language:

COMPUTER LANGUAGE
Introduction:
A language that is acceptable to a computer
system is called a computer language or
programming language.

The process of writing instructions in such a
language is called programming or coding.
TYPES OF LANGUAGE

Computer languages can be broadly classified
into three categories:1.
Machine Language
2.
Assembly Language
3.
High-level Language
MACHINE LANGUAGE

The language which is understood by the
computer without using a translation process.

The computer’s instructions are coded and
stored in the memory in the form of 0s and
1s.

A program written in the form of 0s and 1s is
called machine language program.

A machine-language instruction normally
has a two-part format:•
Operation-code:- which tells the computer what
function (operation or instruction) to perform.
Example:-Arithmetic,
logical,
conditional
operations
•
Operand:- which tells the computer where to
find or store the data or other instructions, which
are to be manipulated.
OPCODE
(operation code)
OPERAND
(Address/location)

Each instruction tells the computer what operation
to perform, and the length and locations of the
data fields, which are involved in the operation.

Every computer has a set of operation codes,
called its instruction set.

Each operation code in the instruction set is
meant for performing a specific basic operation or
function.

Typical operations included in the instruction set of a computer
are as follows:
1.
Arithmetic Operations
2.
Logical Operations
3.
Branch Operations
4.
Data movement operations for moving data between memory
locations and registers.
5.
Data movement operations for moving data from or to one of
the computer’s input/output devices.
ADVANTAGES:

Program written in machine language can
be executed very fast by the computer.
DISADVANTAGE

Machine dependent

Difficult to program

Error prone

Difficult to modify

Time consuming
ASSEMBLY LANGUAGE

1.
Programming in machine language is difficult and error prone because:
A programmer needs to write numeric codes for the instructions in the
computer’s instruction set.
2.
A programmer needs to write the storage locations of data and instructions
in numeric form.
3.
A programmer needs to keep track of the storage locations of data and
instructions while writing a program.

Assembly language programming, which was introduced in 1952, helped in
overcoming the above limitations of machine language.

Assembly language is designed mainly to replace each
machine code with an understandable mnemonic code and
each address with a simple alphanumeric string.

A language, which allows instructions and storage locations
to be represented by letters and symbols, instead of
numbers, is called an assembly language or symbolic language
WHAT IS AN ASSEMBLER ?

The assembler of a computer system is a
system software, supplied by the computer
manufacturer.

A program which translate an assembly
language
program
into
a
machine
language program is called an assembler.

The process of translating an assembly
language program into its equivalent
machine language program:-
input
Assembly language program
Assembler
output
Machine language program
One- one correspondence
Source Program
Object Program
ADVANTAGES…

Advantages of assembly language over
Machine Language:•
Easier to understand and use
•
Easier to locate and correct errors
•
Easier to modify
•
No worry about addresses
•
Efficiency of Machine Language
LIMITATIONS:

The following limitations of machine
language are not solved by using
assembly language:•
Machine dependent
•
Knowledge of hardware required
•
Machine level coding

Machine Language & Assembly Language has the following
Limitations:
1.
They are machine Dependent.
2.
Programmers are required to have a good knowledge of the
internal structure of computers.
3.
It is error prone, difficult & time consuming.

Due to these limitations they are called low level languages.
HIGH-LEVEL LANGUAGE

High-level programming languages were designed to overcome
the limitations of assembly language and machine language.

Features of high-level language:•
•
They are machine independent.
They don’t require the programmers to know anything about
the internal structure of the computer on which high-level
language will be executed.
•
They don’t deal with the machine-level coding.
WHAT IS COMPILER ?

High-level language must be converted into
its equivalent machine language.

A compiler is a translator program, which
translates a high-level language into its
equivalent machine language.

A process of translation is called compilation.

The process of translating an high-level
language
program
into
its
equivalent
machine language program:-
input
High-level language program
Source Program
Compiler
output
Machine language program
Object Program
COMPILERS
Figure 8.1 Compilation process
WHAT IS INTERPRETER ?

An interpreter is another type of translator, which is used for
translating programs written in high-level languages.

It takes one statement of a high-level language program,
translates it into machine language instructions, and then
immediately
executes
the
resulting
machine-language
instruction.
input
High-level language program
Interpreter
(translates and
executes
statement-bystatement)
output
Machine language program

Advantages of Interpreter:•
As compared to compilers, interpreters are
easier to write.
•
They also require less memory space for
execution than compiler.
•
Interpreters make it easier and faster to
correct programs.

Disadvantages of interpreters:•
Interpreters are slower than compilers when
running a finished program.
ADVANTAGES OF HIGH-LEVEL LANGUAGE:
•
Machine independence
•
Easier to learn and use
•
Fewer errors
•
Lower program preparation cost
•
Better documentation
•
Easier to maintain
DISADVANTAGES OF HIGH-LEVEL LANGUAGE
•
Lower efficiency
•
Less flexibility
EXAMPLES:
Some examples of high-level languages are:•
FORTRAN
•
COBOL
•
BASIC
•
PASCAL
•
C
•
Object-oriented langauge (JAVA, C++ etc.).
CHARACTERISTICS OF A GOOD PROGRAMMING LANGUAGE:

Simplicity

Naturalness

Abstraction

Efficiency(good language translator)

Structuredness

Compactness

Locality

Extensibility

Suitability to its Environment
SELECTING A LANGUAGE FOR CODING:

The following factors generally influence the
selection process:•
Nature of the application
•
Familiar with language
•
Ease of learning the language
•
Availability of program development tools
•
Execution efficiency
•
Feature of a good programming language (simplicity,
naturalness, abstraction etc)
PROGRAMMING PARADIGMS
 Why are there hundreds of programming languages in use today?
 Some programming languages are specifically designed for use in certain
applications.
 Different programming languages follow different approaches to solving
programming problems
 A programming paradigm is an approach to solving programming
problems.
 A programming paradigm may consist of many programming languages.
Common programming paradigms:
 Imperative or Procedural Programming
 Object-Oriented Programming
 Functional Programming
 Logic Programming
PROGRAMMING PARADIGMS: IMPERATIVE
 In this paradigm, a program is a series of statements containing variables.
 Program execution involves changing the memory contents of the computer
continuously.
 Example of imperative languages are: C, FORTRAN, Pascal, COBOL etc
Advantages
 low memory utilization
 relatively efficient
 the most common form of programming in use today.
Disadvantages
difficulty of reasoning about programs
difficulty of parallelization.
Tend to be relatively low level.
PROGRAMMING PARADIGMS: OBJECT-ORIENTED
 A program in this paradigm consists of objects which communicate with
each other by sending messages
 Example object oriented languages include: Java, C#, Smalltalk, etc
Advantages
Conceptual simplicity
Models computation better
Increased productivity.
Disadvantages
Can have a steep learning curve, initially
Doing I/O can be cumbersome
PROGRAMMING PARADIGMS: FUNCTIONAL
 A program in this paradigm consists of functions and uses functions in a similar
way as used in mathematics
 Program execution involves functions calling each other and returning
results.
 Example functional languages include: LISP, Haskell
 Advantages
 Small and clean syntax
 Better support for reasoning about programs
 They allow functions to be treated as any other data values.
 They support programming at a relatively higher level than the imperative
languages
 Disadvantages
Difficulty of doing input-output
Functional languages use more storage space than their imperative cousins
PROGRAMMING PARADIGMS: LOGIC
 A program in the logic paradigm consists of a set of predicates and rules of inference.
 Predicates are statements of fact like the statement that says: water is wet.
 Rules of inference are statements like: If X is human then X is mortal.
 The predicates and the rules of inference are used to prove statements that the
programmer supplies.
 Example: Prolog
 Advantages
 Good support for reasoning about programs
 Can lead to concise solutions to problems
 Disadvantages
 Slow execution
 Limited view of the world
 That means the system does not know about facts that are not its predicates and
rules of inference.
 Difficulties in understanding and debugging large programs
WHICH PROGRAMMING PARADIGM IS BEST?
 Which of these paradigms is the best?
 The most accurate answer is that there is no best paradigm.
 No single paradigm will fit all problems well.
 Human beings use a combination of the models represented by these
paradigms.
 Languages with features from different paradigms are often too complex.
 So, the search of the ultimate programming language continues!