[go: up one dir, main page]

0% found this document useful (0 votes)
7 views25 pages

Unit-1

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 25

UNIT- I

Fundamentals of
Programming

Syllabus
Importance of Studying Programming Languages, History of Programming Languages, Impact of
Programming Paradigms, Role of Programming Languages, Programming Environments. Impact of
Machine Architectures: The operation of a computer, Virtual Computers and Binding Times.
Programming paradigms - Introduction to programming paradigms, Introduction to four main
Programming paradigms- procedural, object oriented, functional, and logic and rule based.

Contents
1.1 Importance of Studying Programming Languages

1.2 History of Programming Languages

1.3 Role of Programming Languages

1.4 Programming Environments

1.5 Impact of Machine Architectures

1.6 Programming Paradigms. .... Marks 6

1.7 Multiple Choice Questions

(1-1)
Principles of Programming Languages 1-2 Fundamentals of Programming

Importance of Studying Programming Languages


Following are the reasons for studying the programming language concepts -

1) Increased capacityto express ideas :


* The study of different programming languages makes the programmer with variety
of programming constructs.

* In this study, programmer can understand various data structures, control


structures abstractions and their ability.
e Then they can use suitable programming constructs to express the ideas they want
to implement.

2) Improved background for choosing appropriate language :


e By the knowledge of various programming languages, one can be aware of its
variety of features.
* Hence while developing a software application programmer can make appropriate
selection of the language whose features are most applicable.
* For example — if application requirement is use of GUI then the programmer will
choose Visual basic as a programming language.
3) Increased ability to learn a new language :
* Due to the knowledge of programming constructs and implementation techniques,
programmer can learn new language easily.
4) Better understanding of significance of implementation :
e By learning and understanding different languages, programmer can know the
reasons behind the language design.
* This knowledge leads to use the language more intelligently.
5) Better use of languages that are already known:
« By studying the concepts of programming languages, programmers can learn about
previously unknown and unused parts of the languages they already use and begin
to use those features.
6) Overall advancement of computing :
« By understanding variety of features of programming languages such as arrays,
dynamic arrays, strings, dynamic memory allocation, generic programming - the
programmer can use these features for advance level implementation and
computing.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-3 Fundamentals of Programming

Review Question

| 1. Explain the importance


of studying programming language.

History of Programming Languages

1) Scientific applications :
e The scientific applications require large numbers of floating point computations.
© Ittypically makes use of arrays.
* The programming language used is - Fortran.

2) Business applications :
« The business applications are characterized by facilities of producing variety of
reports.

* Itrequires use of decimal numbers and characters data.


* It also needs an ability to specify decimal arithmetic operations.
* The programming language preferred for building the business applications is -
COBOL.

3) Artificial intelligence :
* The artificial intelligence is an area in which the computations are symbolic rather
than numeric. Symbolic computation means that symbols, consisting of names
rather than numbers.
« Symbolic computation is more conveniently done with linked lists of data rather
than arrays.
« This kind of programming sometimes requires more flexibility than other
programming domains
* The programming language used in this area of applications is - LISP.

4) Systems programming :
* System programming is a system software which consists of collection of operating
system and programming support tools.
* The system software is used continuously, hence it needs to be efficient.
« It should also have a support for interfacing with external devices to be written.
(For example - some support programs for plug and play devices).
e The general programming languages such as C, C++ are usually preferred for
system programming.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-4 Fundamentals of Programming

5) Web software :
e The world wide web software is used to represent some dynamic web contents,
representation of text, audio or video data, contents containing some computations
and so on.
It need a support for variety of languages from markup languages (For example -
HTML), scripting(For example - PHP), to general-purpose(For example -Java).

Role of Programming Languages

Evolution of Major Programming Languages

FORTRAN |:
It is designed for new IBM 704 , which had index registers and floating point
hardware.
From this language onwards the idea of compilation came into existence.
The first implemented version of Fortran has following features -
o Names could have up to six characters.
o Post-test counting loop such as DO was present.
oe It has formatted I/O
o It allows user defined subprograms.
o There were no data typing statements

FORTRAN Il:
e It was distributed in 1958
Independent compilation was supported for FORTRAN II

FORTRAN IV,77,90 :
e Itis evolved during 1960-62
e It has explicit type declarations
There was logical selection statement
Subprogram names could be parameters
It was standardized as FORTRAN 66 in 1966
In FORTRAN 77 the character sting handling features was introduced. IF-THEN-
ELSE statement were introduced.
Most significant changes took place in FORTRAN 90 by allowing use of modules,
dynamic arrays, pointers, recursion,CASE statements, parameter type checking.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-5 Fundamentals of Programming

Functional Programming: LISP :


* Itis a list processing language.
* This language is used in the research of Al.
* The syntax is based on lambda calculus.

ALGOL 60:
« It supports the block structure.
« It has two parameter passing methods.
¢ It supports the subprogram recursion.

COBOL :
¢ The first macro facility in a high level language.
e It has a support for hierarchical data structures.
¢ It contains nested selection statements.
« Long names for variables up to 30 characters were allowed with hyphens.
e It has separate data division.

BASIC :
* Itis easy to use and learn.
¢ The current popular version of BASIC is visual basic.

PLI:
« It was designed by IBM and SHARE.
* Characterized by dynamic typing and dynamic storage allocation
« Variables are untyped i.e. A variable acquires a type when it is assigned a value
* Storage is allocated toa variable when it is assigned a value.

PASCAL :
¢ Itis designed initially for teaching structured programming.
¢ It was small, simple and easy to learn.

¢ Itis developed in 1972 for system programming.


e It has powerful set of operators.
* Though designed as a systems language, it has been used in many application
areas.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-6 Fundamentals of Programming

PROLOG :
* Itis based on formal logic.
* Itis a Non-procedural language.
* Itis considered to be intelligent database system that uses an inferencing process to
infer the truth of given queries.
¢ Itis comparatively inefficient.

ADA:
* For design of this language required huge design effort, involving hundreds of
people, much money, and about eight years.
¢ By allowing use of packages, ADA has a support for data abstraction.
* It support the exception handling mechanism.
* It allows the use of generic units and concurrency mechanism.
« It contains more flexible libraries.

¢ Itis developed as Bell labs in 1980.


¢ It support for both procedural and object oriented features.

JAVA:
« Developed by Sun Microsystems in 1990.
* Itis based on CH
e Itsupports only OOP.
¢ It contains references but no pointers.
¢ It hasa facility and support for applets and concurrency.
« It has libraries for applets, GUIs, database access.
¢ Itis widely used for web programming.

Scripting Languages for WEB :


¢ Various scripting languages such as Perl, PHP, Python, JavaScript, Ruby and so on
are used as a scripting languages for web programming.
-NET Language : C#:
¢ Itis based on C++, Java, and Delphi.

¢ It includes pointers, delegates, properties, enumeration types, a limited kind of


dynamic typing, and anonymous types.
e Is evolving rapidly.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-7 Fundamentals of Programming

Markup/Programming Hybrid Languages :


e XSLT: eXtensible Stylesheet Language Transformation (XSTL) transforms XML
documents for display.
Java Server Pages : a collection of technologies to support dynamic Web documents.

Attributes of Good Language


Various attributes of good languages are -
1. Clarity, simplicity and unity : The programming language should provide the
conceptual framework for thinking about the algorithm. It should provide the
clear, simple and unified set of concepts that can be used as a primitives for
developing the algorithms. The language should allow to use different concepts
with the rules for their combinations with ease and simplicity. This attribute is
called conceptual integrity.
The syntax of the language should be such that readability of the program can be
increased.
. Orthogonality : In context of programming languages, a programming construct is
said to be orthogonal if these constructs can be freely used in combination with
each other. The orthogonallity features expects that the meaning is context
independent. For instance - Pointer should be able to point to any type of variable
or data structure.
This feature makes the language easier to learn and programs are easier to write.
. Naturalness for application : The syntax of a programming language should be
such that it should follow logical structure of the algorithm. Various algorithms
such as sequential algorithms, concurrent algorithms, logic algorithms and so on
have different natural structures which should be represented by the programming
languages. The language should provide appropriate data structures, operations,
and control structures for the problem to be solved.
. Abstraction : Abstraction means hiding the implementation details. This feature
allows the programmer to define and use the complicated structure in such a way
that the implementation details can be ignored. By this attribute - Programmer can
concentrate only on abstract properties without bothering for their implementation
details. ADA and C++ are the languages that support for abstraction feature.
. Program verification : The reliability of programs written in a language is always a
major issue. There are various techniques for program verification. One of the
techniques of program verification is to use test input data. In this technique, the

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-8 Fundamentals of Programming

program is executed with test input data and the output is checked against the
specifications.
If the semantic and syntactic structure is simple then the program verification
becomes simplified.
. Program environment : The programming environment includes well-documented
implementations, special editors and testing packages, version control services and
so on. The technical structure of programming language has a great influence on
use of programming environment appropriately.

. Portability : Portability is a feature by which the program that work on one


platform can be modified to work on other platform.
. Cost of use : The cost is major element in evaluation of any programming language.
The cost can be computed for various factors such as -
a) Cost of program execution : Cost of program execution is particularly important
for large production programs that will be executed repeatedly. The program
execution cost is greatly reduced due to use of optimizing compilers, efficient
register allocation, and design of efficient runtime support mechanism.
b) Cost of program translation : For compiling the large programs/systems, the
compilers take too much time. This increases the overall cost. In such a case, it is
important to have a fast and efficient compiler rather than a compiler that
produces optimized executable code.
c) Cost of program creation, testing and use : The cost is involved in program
designing, coding, testing and modifying. The Smalltalk and Perl are cost
effective languages in this aspect.
d) Cost of program maintenance : The maintenance cost can be four times more
than that of development cost. The cost of maintenance depend on various
characteristics of the language mainly it is dependent upon readability.

Review Questions

1. Explain the Evolution of Major Programming Languages.


2. What are the attributes af Good language ?

Programming Environments
Definition : Programming environment is an environment in which the programs can
be created and tested.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-9 Fundamentals of Programming

Programming Environment consists of a collection of support tools that are used in


software development. Each support tool is basically one kind of program which is used
by the programmer during the stages of creation of program. These tools are editors,
debuggers, verifiers, data generators and so on,

Effect on Language Design


The programming environment influences on language design in two major areas
namely separate compilation and testing and debugging.

(1. Separate Compilation 2. Testing


/ Debugging }

Separate compilation :
There are varying number of programmers working on design, code and test the parts
of programs. This require the language to be structured so that individual subprograms
or other parts can be separately compiled and executed without requirement of other
part. Later on these parts are to be merged into a final program.
Separate compilation is difficult because compiling one subprogram may need some
information which is present in some other sub program or sometimes shared data is
also used in the program due to which separate compilation is not possible. To solve this
problem, some languages have adopted certain features that aid separate compilation.
These features are -
1. The statements such as extern can be used to indicate that particular data is used
from other subprogram.
2. Languages use scoping rules to hide names. One subprogram can be contained
within another subprogram so that the name of the outer subprograms are known
to separately compiled subprogram.
3. In object oriented programming, the feature like inheritance can be used to use the
shared data.

Testing and Debugging :


Many languages contain some features that help in testing and debugging. For
example -
1. Breakpoint Feature : By this feature, the programmer can set the breakpoints in
the program. When the breakpoint is reached during the execution of the program,
the execution of the program is interrupted and control is given to the programmer.
The programmer can then inspect the program for testing and debugging.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-10 Fundamentals of Programming

2. Execution Trace Feature : By this feature particular variable or statement can be


tagged for tracing during the execution of the program.
3. Assertions : The assertions is a conditional expression which is inserted as a
separate statement in a program. For example following is a Java Code fragment in
which the assertion is used
System.out.print("Enter your age: ");
int age = reader.nextInt();
Assertion.assert(age< 18, "You are not allowed to vote");

Environment Framework
¢ Environment framework is nothing but the collection of infrastructure services that
can be used for program development purpose. These services are data repository,
Graphical user interface, security and communication services.
¢ Borland JBuilder is a programming environment that provides integrated compiler,
editor and debugger for Java development.
« The modern programming environment makes use of Visual Studio .NET for
developing the applications using C#, Visual Basic, .NET, Jscript, J# and so on.

* Unix is an old programming environment and has a strong support for various
powerful tools for software production and maintenance. The UNIX GUI runs on
the top of basic UNIX kernel. Typical examples of such GUI are GNOME and KDE.

Review Questions

1. What is programming environment ? Explain the effect of programming enviranment on


language design.
2. Explain the concept of environment framework in programming environment.

Impact of Machine Architectures

Operation of a Computer
Working of any computer is based on the software present in it. The software contains
collection of programs. These programs are created using suitable programming
languages.
A computer consists of six major components that are associated with the
programming languages. These components are —

1. Data
« Inany programming language there are variety of data items and data structures.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-11 Fundamentals of Programming

* The built in data types can be directly manipulated by hardware primitive


operations. Such built in data types are — integer, floating point numbers, double
precision floating point numbers, and strings

¢ The data is stored and processed within data storage components of a computer.
The three major data storage components are —
o Main memory: Main memory consists of bits subdivided into fixed length words.
o High-speed Registers: The contents of registers represent either data or the
memory address of main memory containing data.
o External Files: The external files is generally stored on hard disk or on CD ROM.
It contains records.

External Files
and
InputtOutput

Main Memory

[rian Speed Registers

Fig. 1.5.1 Data storage components

2. Primitive Operations

« A computer contains a set of built-in primitive operations such as addition,


multiplication, subtraction and division.

* The primitive operations are also used for controlling the sequence of execution of
programming statements.

3. Sequence Control
* Computer must provide the mechanism for controlling the flow of execution of
programming instruction. This mechanism is called as sequence control.
¢ Various primitive operations are used for sequence control. These operations
transfer the control flow from one memory location to another.
« The next instruction to be executed is determined by the special purpose register
called program counter(PC).
« The mechanism of execution of programming instruction is illustrated by following
figure.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-12 Fundamentals of Programming

Fetch Next Instruction

Decode Instruction

Fetch Designated Operands

Execute
Primitive Operations

Halt operation
No halt operation

Stop

Fig. 1.5.2 Steps for Program Execution

4. Data Access
Computer provides a controlling mechanism for supplying data for execution of
programming instruction. This mechanism is called data access.

5. Storage Management
« Computer provides the mechanism for controlling the storage for programs and
data resources.
« There are three types of storage components in computer and those are — (i) Main
Memory (ii) High speed Registers and (iii) External Files.
* Sometimes the speed of CPU and main memory does not get synchronized. Hence a
special memory called cache memory is used.
* Acache memory is high speed small memory situated in between the main memory
and CPU. The data present in the cache memory is immediately available CPU.

6. Operating Environment
* Computer provides the mechanism by which external programs help in execution
of application or user programs which constitutes the programming environment.
¢ The operating environment consists of peripheral storage and I/O devices.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-13 Fundamentals of Programming

Translators and Virtual Architectures


« The process of translation of a program from high level programming language to
low level machine language is performed in following steps -
1. The program modules are separately translated into relocatable machine code.
This translator is called as compiler.
2. These translated modules are linked together in a relocatable unit. This task is
carried out by linker or linkage editor.
3. Finally the complete program is loaded into the memory as an executable
machine code. This task is carried out by loader.
Source
program
| Compiler

Relocatable
machine code

Linker

Single relocatable
unit

| Loader

Executable
unit

Input data—e Interpreter Output data


(executed result)

Fig. 1.5.3 Language processing using translation

The modern translation technique uses the combined two technique - translation and
then interpretation. That means the source code is translated into intermediate code and
then the intermediate code is interpreted.

Methods of Program Implementation


The three methods of language implementation are -
1) Compilation : This is a process in which the high level programs are translated into
machine language.
2) Pure interpretation : In this process, programs are interpreted line by line to target
program.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-14 Fundamentals of Programming

Source Program

Input data ——+ | Interpreter

Result

Advantages:
1. Modification of user program can be easily made and implemented as execution
proceeds.
2. Type of object that denotes a variable may change dynamically.
3. Debugging a program and finding errors is simplified task for a program used
for interpretation.
4. The interpreter for the language makes it machine independent.

Disadvantages :
1. The execution of the program is slower.
2. Memory consumption is more.

3) Hybrid implementation system : In this system the programs are translated using
both interpreter and compiler.
* Using compilers the high level programs are translated into intermediate language.
These intermediate languages are easy to interpret. The interpreter interprets the
intermediate language to form the machine code.
« Examples - Perl is implemented using with hybrid implementation system. Initially
implementation of Java were all hybrid. The intermediate form of Java code is
called as byte code. This byte code provides the facility of execution of the code on
any platform. Thus portability to any machine(Platform independence) can be
achieved using byte code.
¢ The Just-In-Time (JIT) compiler is a component of the Java Runtime Environment
that improves the performance of Java applications at run time. Java programs
consists of classes, which contain platform neutral bytecode that can be interpreted
by a Java Virtual Machine(JVM) on many different computer architectures. At run
time, the JVM loads the class files, determines the semantics of each individual
bytecode, and performs the appropriate computation.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-15 Fundamentals of Programming

Source Program

Lexical analyzer

Syntax analyzer

Intermediate code
generator

Input
data ——» Interpreter

Results

Fig. 1.5.4 Hybrid implementation system

Difference between Compiler and Interpreter

Interpreter Compiler

Demerit : The source program gets interpreted Merit: In the process of compilation the
every time it is to be executed, and every time program is analyzed only once and then
the source program is analyzed. Hence the code is generated. Hence compiler is
interpretation is less efficient than Compiler. efficient than interpreter.

The interpreters do not produce object code. The compilers produce object code.

Merit : The interpreters can be made portal Demerit : The compilers has to be present
because they do not produce object code. on the host machine when particular
program needs to be compiled.

Merit : Interpreters are simpler and give us Demerit : The compiler is a complex
improved debugging environment. program and it requires large amount of
memory.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-16 Fundamentals of Programming

Concept of Preprocessor
e Definition : Preprocessor is a program that processes a program just before the
program is compiled.
Preprocessor instructions are embedded in the program.
Preprocessor macros (instructions) are commonly used to specify that code from
another file is to be included.
For example : The C preprocessor expands #include or #define in the following
manner -

o #include "mytestfile.h"
causes the preprocessor to copy the contents of mytestfile.h into the program at
the position of the 4include.
o #define SIZE5
In the program we can declare an array of size 5 in following manner -
int a[SIZE];

Virtual Computers
Definition of Virtual Machine : Virtual machine is a piece of software which
simulates the actual machine environment. An implementation of programming
language requires that the programs in the language are analysed and then
translated into a form that can be run by interpreter i.e. on virtual machine first and
then on actual real machine.
For a virtual machine environment the source program is translated into an
intermediary abstract form which is then interpretively executed.
In this case, the source program first goes through three stages such as lexical
analyser, syntax analyser and type checker. Then the abstract syntax obtained from
these three phases is interpreted to get the translated output.
Due to this feature it is possible to execute the abstract code on any desired
platform.
For example — Java virtual machine is a kind of virtual machine which plays an
important role in achieving the platform independence.
The general structure of virtual machine is as shown in Fig. 1.5.5.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-17 Fundamentals of Programming

Source
program

| Lexical analyzer [+1 Syntax analyzer || Type checker

Abstract
syntax
Input —+} Interpreter | Computer

Output

Fig. 1.5.5 Structure of virtual machine

Binding and Binding Times


« Any program contain various entities such as variables, routines, control statements
and so on. These entities have special properties. These properties are called
attributes. For example - the programming entity routine or function has number
of parameters, type of parameters, parameter passing methods and so on.
Specifying the nature of attributes is called binding.
¢ The time at which the choice for binding occurs is called binding times.
e There are various classes of Binding types and these are represented by following
figure —

Classes of binding times.

Execution ae Language Language


time Translation time implementation definition
time time
(Dynamic binding) (Static binding) (Static binding) (Static binding)

On entry t+—— By
of subpragram programmer

—— At arbitrary ->—— By
points translator
L___ py
Loader

Fig. 1.5.6 Classes of binding times

1. Execution Time
* There are many bindings that are performed during execution of the program.
These type of binding are also called as dynamic binding or Run time binding.

TECHNICAL PUBLICA Tions® - Anup thrust for knowledge


Principles of Programming Languages 1-18 Fundamentals of Programming

¢ At entry to a block or subprogram: At the entry of subprogram the binding takes


place between actual to formal parameters. There can be binding of variables with
their values.
¢ At arbitrary points during Program execution: At arbitrary points during program
execution the variables are assigned with values.

2. Translation Time
¢ Chosen By Programmer: In this binding, declaration of bind types to variable name
occurs. Similarly the binding between values and constants occur.
« Chosen by Loader: Some bindings are chosen by loader. For example — global
variables to location source program to object program representation.

3. Language Implementation Time


¢ In this type of binding, bind the values to the representation in computer.
* Also there is binding of operations and statements to semantics of operations.

4, Language Definition Time:


* Most of the structures of programming languages is fixed at the time the language
is defined. Hence binding occurs as per the structure of the program that has been
defined at the time of its definition. For example —
“DO” is a reserved word in PASCAL but not in FORTRAN.

Early and Late Binding

Early Binding Late Binding

It happens at compile time. It happens at run time.

The method definition and the method call are The method definition and a method call are not
linked during the compile time. This happens bound until run time.
when all information needed to call a method is
available at the compile time.

It is more efficient It is more flexible.

Review Questions

What is the difference between compiler and interpreter ?


NR

Explain the concept of virtual computer.


Explain various classes of binding times.
ww

What is the difference between early binding and late binding ?

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-19 Fundamentals of Programming

Programming Paradigms SPPU : Dec.-17, Marks 6

Definition : Programming paradigm can be defined as a method of problem solving


and an approach to programming language design.

Various types of programming paradigm are -


1. Imperative or procedural programming

2. Object oriented programming


3. Functional programming

4. Logic programming
Examples of various programming languages based on the above mentioned
paradigm is as shown by following table

Imperative Object Functional Logic


programming oriented programming programming
ALGOL Smalltalk LISP Prolog

COBOL Simula Haskell


ADA C+ APL

Cc Java

PASCAL

FORTRAN

Let us discuss them in brief.

Imperative Programming
The Latin word impetrate means to command. Hence this language is command
driven or statement oriented language.
The imperative programming is also called as procedural programming language.
A program consists of sequence of statements. After execution of each statement the
values are stored in the memory.
The central features of this language are variables, assignment statements, and
iterations.

Examples of imperative programming are - C, Pascal, Ada, Fortran and so on.

Merits :
1. Simple to implement.
2. These languages have low memory utilibzation.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-20 Fundamentals of Programming

Demerits :
1. Large complex problems can not be implemented using this category of language.
2. Parallel programming is not possible in this language.
3. This language is less productive and at low level compared to other programming
languages.

Object Oriental Programming


In this language everything is modeled as object. Hence is the name.
This language has a modular programming approach in which data and functions are
bound in one entity called class.
This programming paradigm has gained a great popularity in recent years because of
its characteristic features such as data abstraction, encapsulation, inheritance,
polymorphism and so on.
Examples of object oriented programming languages are - Smalltalk, C++, Java,

Merits :
1. It provides a modular programming approach.
2. It provides abstract data type in which some of the implementation details can be
hidden and protected.
3. Modifying the code for maintenance become easy, due to modules in the program.
Modification in one module can not disturb the rest of the code.
4. Finding bugs become easy.
5. Object oriented programming provides good framework for code library from
which the software components can be easily used and modified by the
programmer.

Demerits :
1. Sometimes real world objects can not be realized easily. Hence it is complex to
implement.
2. Some of the members(data or methods) of the class are hidden. Hence they can not
be accessed by the objects of other class.
3. In object oriented programming everything is arranged in the form of classes and
modules. For the lower level applications it is not desirable feature.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-21 Fundamentals of Programming

Functional Programming
In this paradigm the computations are expressed in the form of functions.
Functional programming paradigms treat values as single entities. Unlike variables,
values are never modified. Instead, values are transformed into new values.

Computations of functional languages are performed largely through applying


functions to values, i.e., (+ 10 20). This expression is interpreted as 10 + 20. The result 30
will be returned.
For building more complex functions the previously developed functions are used.
Thus program development proceeds by developing simple function development to
complex function development.
Examples of function programming are LISP, Haskell, ML

Merits :
1. Due to use of functions the programs are easy to understand.
2. The functions are reusable.
3. It is possible to develop and maintain large programs consisting of large number of
functions.

Demerits :
1. Functional programming is less efficient than the other languages.
2. They consume large amount of time and memory for execution.
3. Purely functional programming is not a good option for commercial software
development.

Logic Programming
In this paradigm we express computation in terms of mathematical logic only. It is also
called as rule based programming approach.
Rules are specified in no special order.
It supports for declarative programming approach. In this approach how the
computations take place is explained.
The logic paradigm focuses on predicate logic, in which the basic concept is a relation.
Example of Logic programming is Prolog.

Merits :
1. This programming paradigm is reliable.

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-22 Fundamentals of Programming

2. The program can be quickly developed using this approach as it makes use of
true/false statements rather than objects.
3. Itis best suitable for the problems in which knowledge base can be established.

Demerits :
1. Execution of the program is very slow.
2. True/false statements can not solve most of the problems.

3. It can solve only limited set of problems efficiently.

Review Questions

1. Explain the programming paradigm in detail.


2. List the programming paradigms. For any three state which programming languages are based
on them and how ? SPPU : Dec.-17, Marks 6

Multiple Choice Questions

Q.1 What is the relationship between reliability and failure ?


[al Direct relation [b] Inverse relation
No relation [a] Varying relation depending upon the situation
Explanation : As reliability increases, the failure decreases. Hence it is an inverse
relation.

Q.2 The language qualities that support reliability are


[al writability [b] readability
simplicity all of these

Q.3 Language efficiencycan be achieved by__—_ss«j.

[al maximum speed [b] less memory consumption

reusability all of these

Q.4 The feature by which the program that work on one platform can be modified on other
platform is called as
[al reusability [b] portability
robustness locality

Q.5 For specifying the syntax of a language is used.

[al context free language [b] regular expression

finite automata none of these

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-23 Fundamentals of Programming

Explanation : The context free grammar consists of set of production rules using which it
is possible to specify the syntactic rules of a language.

Q.6 Syntax of a program means -


[al Format of a program [b] Meaning of a program
Simply content of a program [d] None of these

Q.7 Semantic of a program means -

[al Format of a program [b] Meaning of a program

Simply content of a program [d]None of these

Q8 Aprogram that interprets each line of high level program at the time of execution is
called .
[al translator [b] interpreter
instructor [d] executor

Explanation : Interpretation is a process in which every source language instruction is


directly executed.

Q.9 Aprogram which translates high level programming language into machine code is
called .
[al translator [b] compiler
[c] assembler [a] none of these

Q.10 Variable names resolving is based on :

[al Source language [b] Assembler and loader implementation

[c] Compiler and linker implementation

[a] None of these

Q.11 The set of rules used in context free grammar are called as___

[al terminals [b] non terminals


production rules [d] start symbol

Q.12 Pascal inventor Niklaus Wirth designed the language specially for :

[al Use on any type of operating system

[b] Helping to promote use of personal computers

[c] Teaching programming to students

[a] High speed computing

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-24 Fundamentals of Programming

Q.13 Which was the first language for scientific applications ?

[a] ALGOL 60 [b] FORTRAN


LISP [d] COBOL
Q.14 Which was the first high level language developed for business purpose ?
[a] ALGOL 60 [b] Lisp
COBOL [d] FORTRAN
Q.15 Which languages necessarily need heap allocation in the runtime environment ?

[al Those that support recursion

[b] Those that use dynamic scoping

Those that allow dynamic data structures

[a] Those that use global variables

Q.16 What is the name of the category of programming languages whose structure is dictated by
the von Neuman computer architecture ?

[al Imperative [b] Functional


Constraint [d] Denotational

Q.17 Which one of the following is NOT performed during compilation ?

[al Dynamic memory allocation [b] Type checking

Symbol table management [d] Inline expansion

Q.138 is a piece of software which simulates the actual machine environment.

[al Compiler [b] Debugger

Virtual machine [a] Interpreter

Q.19 The classe(s) of binding times is/are

[al Execution time [b] Translation time

both a and b [d] None of these

Q.20 Execution time is actually


[al dynamic binding [b] static binding
None of these

Q.21 __is defined by Programmer, Loader or translator

[al Execution time [b] Translation time

Language implementation time [a] Language definition time

TECHNICAL PUBLICATI ons® - Anup thrust for knowledge


Principles of Programming Languages 1-25 Fundamentals of Programming

Q.22 Static bindingis


[al Translation time [b] Language implementation time
Language definition time [a] All of the above

Q.23 is a program that processes a program just before the program is compiled.

[al Preprocessor [b] Interpreter

Compiler [a] Assembler

Answer Keys for Multiple Choice Questions :

Qa b Q.2 d Q3 d Qa b
Qs a Q.6 a Q7 b Qs b
Q9 b Q.10 c Qa c Qaz c
Q.3 b Q.4 c Q.15 c Q.16 a
Q.17 a Q.18 c Q.19 c Q.20 a
Q.21 b Q.22 d Q.23 a

QOU

TECHNICAL PUBLICA Tions® - Anup thrust for knowledge

You might also like