Professional Documents
Culture Documents
ECEg - 4182
by
Dr. T.R.SRINIVASAN, B.E., M.E., Ph.D.,
Assistant Professor,
Faculty of Electrical and Computer Engineering,
Jimma Institute of Technology,
Jimma University,
Jimma, Ethiopia
1
Programming Languages
Chapter 1: Introduction
2
Main Topics
• Reasons for studying programming languages
• Programming Domains
• Language Evaluation Criteria
• Influences on Language Design
• Language Categories
• Language Design Tradeoffs
• Implementation Methods
• Programming Environments
3
Why Study PL?
• Increased capacity to express ideas
• Improved background for choosing appropriate
languages
• Increased ability to learn new languages
• Better understanding of the significance of
implementation
• Increased ability to design new languages
• Overall advancement of computing
4
Increased capacity to express ideas
• Programming language constrains
– Control structures
– Data structures
– Abstractions that can be used
• Awareness of language features reduces these
limitations
– Features of one language may be simulated in another
– Study of PLC builds appreciation for language features and
encourages their use
5
Improved background for choosing languages
6
Ability to learn new languages
• A thorough understanding of PLC makes it easier to
see how language concepts are incorporated in the
language being learned
– Understanding data abstraction facilitates learning how to
construct ADTs in C++ or Java
– Understanding PLC terminology makes it easier to
understand manuals for programming languages and
compilers
7
Understanding implementation
• Understanding language implementation
issues leads to
– Understanding why languages are designed the
way they are
– Ability to use a language more intelligently
– Ability to use a language more efficiently when
there is a choice among several constructs:
• Example: recursion vs. iteration
8
Designing new languages
• Programmers occasionally design languages of
some kind or another
– Software system user interface
• Interface design involves PLC techniques
– Lexical analysis
– Parsing
• Criteria for judging user interface are similar to
language design criteria
– Language design influences complexity of the
algorithms that translate it
9
Better use of languages that are
already known
• Study of PLC helps programmers to learn
about previously unknown or unused features
and constructs of the language they already
use
10
Overall advancement of computing
• Why does a particular language become popular?
– Best suited to solving problems in a particular domain
– Those in positions to choose are familiar with PLC
– Those in positions to choose are not familiar with PLC
• ALGOL 60 vs FORTRAN (1960s)
– ALGOL more elegant, better control statements
– Programmers found ALGOL language description difficult
to read, concepts difficult to understand
11
Programming Domains
• Scientific Apps
• The 1st digital computers were invented and
used for scientific application
• Scientific computations
– Simple data structures (array and matrices)
– Large number of floating point computations
• Fortran, Algol
12
System programming
14
Levels of Language in Computing
15
Language Evaluation Criteria
• Readability
• Writeability
• Reliability
• Cost
16
Readability
17
• characteristics that contribute to the
readability of a programming language
• Overall Simplicity
• Orthogonality
• Control Statements
• Data Types and Structures
• Syntax Considerations
18
Readability: Simplicity
• The difficulty in learning a new language increases
with the number of components in the language
• Feature multiplicity negatively impacts readability
– C: x++; ++x; x = x+1; x += 1;
• Operator overloading should be used sensibly
• Simplicity in the extreme: assembly language
19
Readability: Orthogonality
• 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 combinations of primitives is
legal and meaningful
20
Orthogonality
• Example: suppose a language has
– 4 data types (int, float, double, char)
– 2 type operators (array and pointer)
– If the 2 type operators can be applied to
themselves and the 4 data types, a large number
of data structures is possible.
– int[5][2], float***, float*[4], etc.
21
Orthogonality
• The more orthogonal the design, the fewer
exceptions the language rules require.
• C is not very orthogonal:
– There are 2 kinds of structured data types, arrays
and structs; structs can be returned as values of
functions, arrays cannot
– Parameters are passed by value, except for arrays,
which are passed by reference.
22
Orthogonality
• Too much orthogonality can cause problems, such as
ALGOL 68, which had an explosion of combinations
• Functional programming languages such as LISP
provide a good balance of simplicity and
orthogonality
– Single construct, the function call, which can be combined
with other function calls in simple ways
– Functions are first-class objects
23
Readability: Control Statements
• Control statements were introduced relatively
recently as a reaction to indiscriminate use of goto
statements
• FORTRAN had no while loop, so while construct was
implemented with an IF statement and a restricted
GOTO:
20 IF (X .LT. 10) GOTO 30
-- loop statements go here
GOTO 20
30 –- first statement following loop
24
Readability: Data Types and Structures
• Features for user-defined data types enhance
readability.
• Record types for storing employee info vs a
collection of related arrays (FORTRAN):
CHARACTER(LEN=20) NAME(100)
INTEGER AGE(100)
INTEGER EMP_NUMBER(100)
REAL SALARY(100)
25
• suppose a numeric type is used for an
indicator flag because there is no Boolean
type in the language
– timeOut = 1 meaning unclear
– timeOut = true meaning is clear
26
Readability: Syntax Considerations
• The syntax, or form, of the elements of a language has
a significant effect on the readability of programs
• readability are strongly influenced by the forms of a
language’s special words
• Especially important is the method of forming
compound statements
• Designing statements so that their appearance at least
partially indicates their purpose is an obvious aid to
readability
27
Readability: Syntax Considerations
• Identifier forms
– FORTRAN 77 (6 chars max, embedded blanks)
– Original ANSI Basic (a single letter, optionally followed
by a single digit)
• Special words
– Compound statement delimiters
• Pascal: begin..end
• C: { .. } simplicity resulted from fewer reserved words
• Ada: if .. end loop .. end loop
(greater readability resulted from more reserved words)
28
Writeability
• Writability is a measure of how easily a language can be used
to create programs for a chosen problem domain
29
Writeability
• Simplicity and orthogonality
• Support for abstraction
– Process abstraction
– Data abstraction
• Expressivity
– means that a language has relatively convenient, rather than
cumbersome, ways of specifying computations
30
Reliability
• A program is said to be reliable if it performs to its
specifications under all conditions
• Type checking
– Type checking is testing for type errors in a given program
either at compile or run time
– Subscript ranges: Ada vs. C
– Static vs. dynamic type checking
• failure to type check, at either compile time or
run time, has led to countless program errors
31
Exception handling
32
Costs
• Training programmers
– A function of the simplicity and orthogonality of the
language and the experience of the programmers
• Writing programs
– The original efforts to design and implement high-
level languages were driven by the desire to lower
the costs of creating software
33
• Compiling programs
• Executing programs
– A language that requires many run-time type checks
will prohibit fast code execution, regardless of the
quality of the compiler
• Language implementation system
– A language whose implementation system is either
expensive or runs only on expensive hardware will
have a much smaller chance of becoming widely used
34
• Poor reliability
– If the software fails in a critical system, such as a
nuclear power plant or an X-ray machine for
medical use, the cost could be very high
• Maintaining programs
35
36
Influences on Language Design
• Computer architecture
– Imperative languages model von Neumann architecture
– Functional programming languages need a non-von Neumann
architecture to be implemented efficiently
• Programming methodologies
– Top-down design, stepwise refinement
– New s/w design methodology in 1970’s
– incompleteness of type checking and inadequacy of control statements
– Data-oriented vs. procedure-oriented design
– Object-oriented design
– Latest step in data-oriented s/w development (began in early 1980)
– Concurrency (procedure-oriented)
37
38
Language Categories
Imperative Functional
O-O Logic
39
Imperative Languages
fun fact x =
if x <= 0 then 1 else x * fact(x-1);
41
Logic Languages
fact(X,1) :-
X =:= 1.
fact(X,Fact) :-
X > 1,
NewX is X - 1,
fact(NewX,NF),
Fact is X * NF.
44
New Languages
• A clean slate: no need to maintain compatibility with an
existing body of code
• But never entirely new any more: always using ideas from
earlier designs
45
Widely Used: Java
• Quick rise to popularity since 1995 release
• Java uses many ideas from C++, plus some from
Mesa, Modula, and other languages
• C++ uses most of C and extends it with ideas from
Simula 67, Ada, ML and Algol 68
• C was derived from B, which was derived from BCPL,
which was derived from CPL, which was derived from
Algol 60
46
Not Widely Used: Algol
• One of the earliest languages: Algol 58,
Algol 60, Algol 68
• Never widely used
• Introduced many ideas that were used in
later languages, including
48
Imperative ML
dd
fun fact n =
let
val i = ref 1;
val xn = ref n
in
while !xn>1 do (
i := !i * !xn;
xn := !xn - 1
);
!i
end;
49
Non-object-oriented Java
class Fubar {
public static void main (String[] args) {
// whole program here!
}
}
50
Language Design Tradeoffs
• Reliability vs. cost of execution
– Ada’s runtime type checking adds to execution overhead
• Readability vs. writeability
– C and APL
• Flexibility vs. safety
– Pascal variant record is a flexible way to view a data object
in different ways, but no type checking is done to make it
safe
51
Implementation methods
• Compilation
– Translate high-level program to machine code
– Slow translation
– Fast execution
52
53
Implementation methods
• Interpretation
– No translation
– Slow execution
– Becoming rare
• Hybrid implementation systems
– Small translation cost
– Medium execution speed
– Java applets are compiled into byte code
54
Programming Environments
• A collection of tools used in software
development
• UNIX (solaris CDE, Gnome & KDE)
• Borland C++, JBuilder
• integrated compiler, editor, debugger, and file system
for s/w development
• Microsoft Visual C++, Visual Basic
55