PPL Unit01
PPL Unit01
Languages
SE Sem II
Fundamentals of Programming
• Many languages provide features, that when used properly, are of benefit to the programmer
but, when used improperly, may waste large amounts of computer time or lead the
programmer into time-consuming logical errors
• Even a programmer who has used a language for years may not understand all of its
features
• A typical example is recursion—a handy programming feature that, when properly used,
allows the direct implementation of elegant and efficient algorithms. When used
improperly, it may cause an astronomical increase in execution time
Importance of Studying Programming Language
• By understanding how features in your language are implemented, you greatly increase
your ability to write efficient programs
• For example, understanding how data such as arrays, strings, lists, or records are
created and manipulated by your language, knowing the implementation details of
recursion, or understanding how object classes are built allows you to build more
efficient programs consisting of such components.
Importance of Studying Programming Language
• A knowledge of a variety of languages may allow the choice of just the right language
for a particular project, thereby reducing the required coding effort.
• Internet applications are more readily designed using Perl and Java. Knowledge of the
basic features of each language's strengths and weaknesses gives the programmer a
broader choice of alternatives
Importance of Studying Programming Language
5. To make it easier to learn a new language
• A designer of a user interface for a large program such as a text editor, an operating
system, or a graphics package must be concerned with many of the same issues that are
present in the design of a general-purpose programming language
• Many new languages are based on C or Pascal as implementation models. This aspect of
program design is often simplified if the programmer is familiar with a variety of
constructs and implementation methods from ordinary programming languages.
A brief history
of programming languages
Software Evolution
1/0
Machine Language
Assembly Language
10
Evolution of computer languages
Program in machine language
1 00000000 00000100 0000000000000000
2 01011110 00001100110000100000000000000010
3 11101111 000101100000000000000101
4 11101111 10011110 0000000000001011
5 11111000 10101101 11011111 0000000000010010
6 0110001011011111 0000000000010101
7 11101111 00000010 11111011 0000000000010111
8 11110100 1010110111011111 0000000000011110
9 00000011 10100010 11011111 0000000000100001
10 11101111 00000010 11111011 0000000000100100
11 01111110 11110100 10101101
12 11111000 10101110 110001010000000000101011
13 00000110 10100010 11111011 0000000000110001
14 11101111 00000010 11111011 0000000000110100
15 00000100 0000000000111101
16 00000100 0000000000111101
Levels of Programming Languages
High-level program class
class Triangle
Triangle {{
...
...
float
float surface()
surface()
return
return b*h/2;
b*h/2;
}}
13
Evolution of computer languages
Program in machine language
1 00000000 00000100 0000000000000000
2 01011110 00001100110000100000000000000010
3 11101111 000101100000000000000101
4 11101111 10011110 0000000000001011
5 11111000 10101101 11011111 0000000000010010
6 0110001011011111 0000000000010101
7 11101111 00000010 11111011 0000000000010111
8 11110100 1010110111011111 0000000000011110
9 00000011 10100010 11011111 0000000000100001
10 11101111 00000010 11111011 0000000000100100
11 01111110 11110100 10101101
12 11111000 10101110 110001010000000000101011
13 00000110 10100010 11111011 0000000000110001
14 11101111 00000010 11111011 0000000000110100
15 00000100 0000000000111101
16 00000100 0000000000111101
Note:
In this, we convert an Assembly level language to In this, we convert a high-level language to Assembly
machine level language level language to machine level language
In this, it is easy to access hardware component In this, it is difficult to access hardware component
• Charles Babbage:
• Konrad Zuse:
Designed Plankalkül. This notation (never implemented) has features than can
be found in many existing programming languages.
Very low-level languages
• Those are machine languages and assembly languages, machine-dependent
coding systems. They were initially fully binary, and then symbolic.
• There is one native machine language, and usually one assembly language per
processor model.
• Fortran was originally developed by IBM in the 1950s for scientific and
engineering applications, and subsequently came to dominate scientific
computing.
• It has been in use for over six decades in computationally intensive areas such as
numerical weather prediction, finite element analysis,
computational fluid dynamics, geophysics, computational physics, crystallography
and computational chemistry. It is a popular language for
high-performance computing and is used for programs that benchmark and rank
the world's fastest supercomputers.
Fortran
• Fortran was the first effectively implemented high-level language that introduced
variables as we know them now, loops, procedures, statement labels and much
more.
• The earliest versions of Fortran had many unique features, often awkward, later
kept along for compatibility. It is still widely used in engineering applications that
require much array manipulation.
• The newest version, Fortran 90, has converged toward other popular programming
languages.
Algol 60
• It was the first to have block structure, recursion, and a formal definition. It is
not used now, but it is the ancestor of most contemporary languages.
• As far as design goes, Algol 60 was without doubt the most important
innovation in the history of programming languages (so far ).
Cobol
• Business-oriented computations
• very strict program organization
• poor control structures
• elaborate data structures, record type introduced for the first time.
• A combination of features believed (at the time) best in Fortran, Algol 60,
Cobol.
• The first programming language for many programmers: designed to be easy to learn.
• Present-day versions of Basic are full-fledged languages—not "basic", and not easy to learn any more.
Simula 67
• Simula is the name of two simulation programming languages, Simula I and Simula 67,
developed in the 1960s at the Norwegian Computing Center in Oslo, by Ole-Johan Dahl and
Kristen Nygaard. ... Simula is considered the first object-oriented programming language.
• Now unused.
CSI 3125, History, page 33
Algol 68
• ALGOL 68 (short for Algorithmic Language 1968) is an imperative programming language that was
conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much
wider scope of application and more rigorously defined syntax and semantics.
• Imperative programming is a programming paradigm that uses statements that change a program's state
• Full orthogonality.
• Its successors, Modula-3 and Oberon, are even more conceptually appealing,
practically useful—and almost not used at all. (They lost the popularity contest
with C++.)
Ada
• There are, however, two standards: Ada 83 (the original), and Ada 95.
• Ada has been designed to support concurrency in a very neat, systematic way.
C-language
• The implementation language of Unix.
• Relatively low-level.
Lisp
• One of the earliest programming languages.
• For years, the only language for Artificial Intelligence work. (Prolog is 12 years
younger.)
• Lisp's successors are very elegant (Miranda, ML, Haskell) but not nearly as widely
used.
Prolog
• This is a hybrid design, with object orientation added to a completely different base language.
• Text processing:
• Perl
• Python
• Web programming
• JavaScript
• PHP
Role of Programming
Language
Role of Programming Languages
Just like natural languages, programming languages evolve and eventually pass out of use.
Algol from 1960 is no longer used, replaced by Pascal, which in turn is being replaced by
CH—I- and Java. COBOL use is dropping for business applications, also being replaced by
C++. APL, PL/I, and SNOBOL4, all from the 1960s, and
Pascal from the 1970s have all but disappeared.
The older languages still in use have undergone periodic revisions to reflect changing
influences from other areas of computing. Newer languages like C++, Java, and ML reflect
a composite of experience gained in the design and use of these and the hundreds of other
older languages. Some of these influences include
the following:
Influences
1. Computer capabilities.
2. Applications.
3. Programming methods.
4. Implementation methods.
5. Theoretical studies.
6. Standardization.
Attributes of a Good Language
A programming language provides both a conceptual framework for thinking about algorithms and
a means of expressing those algorithms. The language should be an aid to the programmer long
before the actual coding stage. It should provide a clear, simple, and unified set of concepts that
can be used as primitives in developing algorithms.
2. Orthogonality.
• The term orthogonality refers to the attribute of being able to combine various features of a
language in all possible combinations, with every combination being meaningful.
• When the features of a language are orthogonal, the language is easier to learn and programs are
easier to write because there are fewer exceptions and special cases to remember.
Attributes of a Good Language
3. Naturalness for the application.
A language needs a syntax that, when properly used, allows the program structure to reflect the
underlying logical structure of the algorithm. Ideally, it should be possible to translate such a
program design directly into appropriate program statements that reflect the structure of the
algorithm. Sequential algorithms, concurrent algorithms, logic algorithms, and others all have
differing natural structures that are represented by programs in those languages.
• Even with the most natural programming language for an application, there is always a substantial gap
remaining between the abstract data structures and operations that characterize the solution to a problem
and the particular primitive data structures and operations built into a language.
• Ideally, the language should allow data structures, data types, and operations to be defined and
maintained as self-contained abstractions. The programmer may use them in other parts of the program
knowing only their abstract properties without concern for the details of their implementation.
Attributes of a Good Language
5. Ease of program verification.
• The reliability of programs written in a language is always a central concern. There are many
techniques for verifying that a program correctly performs its required function.
• A language that makes program verification difficult may be far more troublesome to use than
one that supports and simplifies verification, even though the former may provide many more
features that superficially appear to make programming easier.
6. Programming environment.
• One important criterion for many programming projects is the transportability of the resulting
programs from the computer on which they are developed to other computer systems
• A language that is widely available and whose definition is independent of the features of a
particular machine forms a useful base for the production of transportable programs.
8. Cost of use.
Cost is certainly a major element in the evaluation of any programming language, but cost
means many different things:
(a) Cost of program execution.
(b) Cost of program translation.
(c) Cost of program creation, testing, and use.
(d) Cost of program maintenance.
Programming Environment
Programming Environments
• The conversion of program text file into binary format you need
software called compiler
Impact of Machine
Architectures
THE OPERATION OF A COMPUTER
• A computer is an integrated set of algorithms and data structures capable of storing and
executing programs.
• A computer may be constructed as an actual physical device using wires, integrated circuits,
circuit boards, and the like, in which case it is termed an actual computer or hardware computer.
• It may also be constructed via software by programs running on another computer, in which
case it is a software-simulated computer.
• The computer that executes the translated programs may either be a hardware computer or a
partially of software.
THE OPERATION OF A COMPUTER
Data
Primitive Operations
Sequence Control
Data Access
Storage Management
Operating Environment
Organization of a conventional computer.
THE OPERATION OF A COMPUTER
1. Data.
Three major data storage components: main
memory, high-speed registers, and external files.
Multiprocessors.
• An assembler is a translator whose object language is also some variety of machine language for an actual
computer but whose source language, an assembly language, represents for the most part a symbolic
representation of the object machine code.
• A compiler is a translator whose source language is a high-level language and whose object language is close to
the machine language of an actual computer, either being an assembly language or some variety of machine
language.
• A loader or link editor is a translator whose object language is actual machine code and whose source language
is almost identical; it usually consists of machine language programs in relocatable form together with tables of
data specifying points, where the relocatable code must be modified to become truly executable.
• A preprocessor or a macroprocessor is a translator whose source language is an extended form of some high-
level language such as C++ or Java and whose object language is the standard form of the same language.
Language Implementations
2. Software simulation (software interpretation).
• Rather than translating the high-level language programs into equivalent machine-language programs, we
might instead simulate, through programs running on another host computer, a computer whose machine
language is the high-level language.
• To do this, we construct a set of programs in the machine language of the host computer that represent the
algorithms (and data structures) necessary for the execution of programs in the high-level language.
• The main simulator program performs an interpretation algorithm decoding and executing each statement
of the input program in the appropriate sequence and producing the specified output from the program.
• we say that the host computer creates a virtual machine simulating the high-level language. When the host
computer is executing the high-level program, it is not possible to tell whether the program is being
executed directly by the hardware or is first converted to the low-level machine language of the hardware
computer.
Virtual Computers
For virtual machine environment the source program first translated into an intermediary
abstract from which is then interpretively executed.
Any program contain various entities such as variables, routines, control statements and so on.
The time at which the choice for binding occurs is called binding times.
Although there is no simple categorization of the various types of bindings, a few main binding
times may be distinguished if we recall our basic assumption that the processing of a program,
regardless of the language, always involves a translation step followed by execution of the
translated program
Binding Time
Binding Time
Many bindings are performed during program execution. These include bindings of variables to their values, as
well as (in many languages) the binding of variables to particular storage locations.
Some aspects of a language definition may be the same for all programs that are run using a particular
implementation of a language, but they may vary between implementations.
A program written in the language that uses a feature whose definition has been fixed at implementation
time will not necessarily run on another implementation of the same language; even more troublesome, it
may run and give different results.
Most of the structure of a programming language is fixed at the time the language is defined, in the sense
of specification of the alternatives available to a programmer when writing a program.
For example, the possible alternative statement forms, data structure types, program structures, and so on
are all often fixed at language definition time.
Binding Time
To illustrate the variety of bindings and binding times, consider the simple assignment statement
X = X + 10
written in a language L. We might inquire into the bindings and binding times of the following elements of this
statement:
1. Set of types for Variable X. : The set of allowable types for X is often fixed at language definition time (e.g.,
only types real, integer, Boolean, set, and character might be allowed).
2. Type of variable X. : The particular data type associated with variable X is often fixed at translation time.
3. Set of possible values for variable X. : If X has data type real, then its value at any point during execution is
one of a set of bit sequences representing real numbers.
4. Value of Variable X. : At any point during program execution, a particular value is bound to Variable X. This
value is determined at execution time through assignment of a value to X.
5. Representation of the constant 10. : The integer 10 has both a representation as a constant in the text of the
program, using the string 10, and a representation at execution time, commonly as a sequence of bits.
6. Properties of the operator +. :The choice of symbol + to represent the addition operation is made at language
definition time.
Binding Time
Introduction of Programming Paradigms
Assume that the user needs to check for new emails. One method is by enabling the inbox notifications. The
user has to enable the notifications only once, and each time a new email arrives, he gets a notification
automatically. Declarative programming is similar to that.
It provides simplicity.
Declarative programming expresses what required result is. It explains the logic of a computation without
describing the control flow.
Introduction of Programming Paradigms
What is Imperative Programming?
To check the new emails, the user can login to gmail and keep refreshing the page to check whether he
got new emails or not.
1. Procedural Programming
Procedural programming can also be referred to as imperative programming.
It is a programming paradigm based upon the concept of procedure calls, in which statements are
structured into procedures (also known as subroutines or functions).
They are a list of instructions to tell the computer what to do step by step, Procedural programming
languages are known as top-down languages.
The coded simplicity along with ease of implementation of compilers and interpreters.
A large variety of books and online course material available on tested algorithms, making it easier to learn.
The code can be reused in different parts of the program, without the need to copy it.
2. Object-Oriented Programming
In this framework, all real-world entities are represented by Classes.
Objects are instances of classes so each object encapsulates a state and behavior.
State implies the fields, attributes of the object and behavior is what you do with the state of the
object and they are the methods.
Inheritance - Inheritance is one of the core concepts of object-oriented programming (OOP) languages. It is
a mechanism where you can derive a class from another class for a hierarchy of classes that share a set of
attributes and methods. It explains how the class hierarchies develop code readability and support to the
reuse of functionality.
Data Abstraction - to Data abstraction is the reduction of a particular body of data to a simplified
representation of the whole. Data abstraction is usually the first step in database design.
3. Functional Programming
The functional programming paradigms has its roots in mathematics and it is language independent.
The key principal of this paradigms is the execution of series of mathematical functions.
The central model for the abstraction is the function which are meant for some specific computation and not
the data structure. Data are loosely coupled to functions.
The function hide their implementation. Function can be replaced with their values without changing the
meaning of the program. Some of the languages like perl, javascript mostly uses this paradigm.
Introduction of Programming Paradigms
Introduction of Programming Paradigms
Features of Functional Programming
•Pure functions – As seen above, if the input is an array, the output will be a new array and the input array will not be
modified. So in case of pure functions, the output depends only on the input.
•Recursion-A recursive function is a function that calls itself during its execution. This enables the function to repeat
itself several times, the result being outputted at the end of each iteration.
•Referential transparency-An expression is said to be referentially transparent if it can be replaced with its
corresponding value without changing the program's behavior. As a result, evaluating a referentially transparent
function gives the same value for fixed arguments. In functional programming, only referentially transparent functions
are considered. They are a lot easier to read and understand.
•Variables are Immutable-In functional programming you cannot modify a variable after it has been initialized. You
can create new variables and this helps to maintain state throughout the runtime of a program.
•Functions are First-Class and can be Higher-Order-A programming language is said to have First-class functions
when functions in that language are treated like any other variable. For example, in such a language, a function can be
passed as an argument to other functions, can be returned by another function and can be assigned as a value to a
variable. Higher-order functions are functions that take at least one first-class function as a parameter.
Introduction of Programming Paradigms
In logic programming we have a knowledge base which we know before and along with the question
and knowledge base which is given to machine, it produces result.
In normal programming languages, such concept of knowledge base is not available but while using the
concept of artificial intelligence, machine learning we have some models like Perception model which is
using the same mechanism.
In logical programming the main emphasize is on knowledge base and the problem. The execution of the
program is very much like proof of mathematical statement, e.g., Prolog
Introduction of Programming Paradigms
Logical programming can be used to express knowledge in a way that does not depend on the
implementation, making programs more flexible, compressed and understandable.
It enables knowledge to be separated from use, i.e. the machine architecture can be changed without
changing programs or their underlying code.
It can be altered and extended in natural ways to support special forms of knowledge, such as meta-level of
higher-order knowledge.
It can be used in non-computational disciplines relying on reasoning and precise means of expression.