Principles of Programming Languages Lecture Notes Unit 1
Principles of Programming Languages Lecture Notes Unit 1
1.2Programming Domains
a) Scientific applications
a. In the early 40s computers were invented for scientific applications.
b. The applications require large number of floating point computations.
c. Fortran was the first language developed scientific applications.
d. ALGOL 60 was intended for the same use.
b) Business applications
a. The first successful language for business was COBOL.
b. Produce reports, use decimal arithmetic numbers and characters.
c. The arrival of PCs started new ways for businesses to use computers.
d. Spreadsheets and database systems were developed for business.
c) Artificial intelligence
a. Symbolic rather than numeric computations are manipulated.
b. Symbolic computation is more suitably done with linked lists than arrays.
c. LISP was the first widely used AI programming language.
d) Systems programming
a. The O/S and all of the programming supports tools are collectively known as its
system software.
b. Need efficiency because of continuous use.
e) Scripting languages
a. A list of commands is kept at one place, called a script, in a file to be executed.
b. PHP is a scripting language used on Web server systems. Its code is embedded in
HTML documents. The code is interpreted on the server before the document is
sent to a requesting browser.
f) Special-purpose languages
a. RPG is an example of these languages.
1.3
I) Readability
Although the last two statements have slightly different meaning from each other
and from the others, all four have the same meaning when used as stand-alone
expressions.
Operator overloading where a single operator symbol has more than one
meaning.
Although this is a useful feature, it can lead to reduced readability if users are
allowed to create their own overloading and do not do it sensibly.
b)Orthogonality
Makes the language easy to learn and read.
Meaning is context independent. Pointers should be able to point to any type of
variable or data structure. The lack of orthogonality leads to exceptions to the
rules of the language.
A relatively small set of primitive constructs can be combined in a relatively
small number of ways to build the control and data structures of the language.
Every possible combination is legal and meaningful.
Ex: page 11 in book.
The more orthogonal the design of a language, the fewer exceptions the language
rules require.
The most orthogonal programming language is ALGOL 68. Every language
construct has a type, and there are no restrictions on those types.
This form of orthogonality leads to unnecessary complexity.
c) Control Statements
It became widely recognized that indiscriminate use of goto statements severely
reduced program readability.
Ex: Consider the following nested loops written in C
i. while (incr < 20)
ii. {
iii. while (sum <= 100
iv. {
1. sum += incr;
v. }
vi. incr++;
vii. }
loop1:
if (incr >= 20) go to out;
loop2:
if (sum > 100) go to next;
sum += incr;
go to loop2;
next:
incr++;
go to loop1:
out:
Basic and Fortran in the early 70s lacked the control statements that allow strong
restrictions on the use of gotos, so writing highly readable programs in those
languages was difficult.
Since then, languages have included sufficient control structures.
The control statement design of a language is now a less important factor in
readability than it was in the past.
II)Writability
It is a measure of how easily a language can be used to create programs for a chosen
problem domain.
Most of the language characteristics that affect readability also affect writability.
a)Simplicity and orthogonality
A smaller number of primitive constructs and a consistent set of rules for
combining them is much better than simply having a large number of primitives.
b)Abstraction
Abstraction means the ability to define and then use complicated structures or
operations in ways that allow many of the details to be ignored.
A process abstraction is the use of a subprogram to implement a sort algorithm
that is required several times in a program instead of replicating it in all places
where it is needed.
c)Expressivity
It means that a language has relatively convenient, rather than cumbersome, ways
of specifying computations.
Ex: ++count
III)Reliability
Iv)Cost
Categories
i.
Training programmers to use language
ii.
Writing programs Writability
iii. Compiling programs
iv.
Executing programs
v.
Language implementation system Free compilers is the key, success of Java
vi.
Reliability
vii.
viii.
b)Programming methodologies
i. 1950s and early 1960s: Simple applications; worry about machine efficiency
ii. Late 1960s: People efficiency became important; readability, better control
structures
a. Structured programming
b. Top-down design and step-wise refinement
iii. Late 1970s: Process-oriented to data-oriented
a. data abstraction
iv.
Middle 1980s: Object-oriented programming
1.5Language Categories
Design Principles
Modularity, abstraction, contracts
Programming languages features
a) Imperative
Central features are variables, assignment statements, and iteration
Ex: C, Pascal
b)Functional Programming
Main means of making computations is by applying functions to given parameters
Ex. Scheme, ML ,LISP, Scheme
c)Logic Programming
Rule-based
Rules are specified in no special order
Declarative Programming
E.g. Prolog
d) Object Oriented Programming
Encapsulate data objects with processing
Inheritance and dynamic type binding
Grew out of imperative languages
Ex C,Java, Pascal
1.8Programming Environments