CHAPTER 1
PRELIMINARIES
SLIDES COURTESY FROM :
“CONCEPTS OF PROGRAMMING LANGUAGES” –BY
ROBERT W. SEBESTA.
PUBLISHED BY PEARSON EDUCATION, INC. USA.
ELEVENTH EDITION. 2016
Md. Rawnak Saif Adib
1 Lecturer
Department of Computer
Science and Engineering
REASONS FOR STUDYING CSC 461
PROGRAMMING LANGUAGE STRUCTURES
Increased ability to express ideas
More expressive power of a language gives a greater
ability to think.
Software with advanced language has fewer
limitations.
Communicate with the computer more effectively.
Example: simulate/replicate objects-oriented
programming in C.
Improved background for choosing appropriate
languages
Choose the most appropriate language rather than the
most familiar one.
Project requirement is more important than personal
2
proficiency.
Example: Java or C or Python?
REASONS FOR STUDYING CSC 461
PROGRAMMING LANGUAGE STRUCTURES
Increased ability to learn new languages
Programming languages are still in a state of
continuous evolution.
Knowing the fundamental concepts of languages
makes it easier to learn a new language.
Only language features matter.
Better understanding of the significance of
implementation
Understanding the implementation issues gives
opportunity gives the ability to use a language
more intelligently.
Program bugs can be fixed.
Performance. 3
REASONS FOR STUDYING CSC 461
PROGRAMMING LANGUAGE STRUCTURES
Better use of languages that are already
known
Learn about previously unknown and unused parts
of the languages that are already used.
Overall advancement of computing
The most popular languages are not always the
best available.
A language became widely used, at least in part,
because those in positions to choose languages
were not sufficiently familiar with programming
language concepts.
4
PROGRAMMING DOMAINS
Scientific applications
The first digital computers were used for
scientific applications.
Large number of floating-point computations
Overall advancement of computing. E.g., Fortran.
Business applications
Started in the 1950s.
Produce reports using decimal numbers and
characters. E.g., COBOL.
Artificial intelligence
Characterized by the use of symbols rather than
numbers manipulated. E.g., LISP. 5
Needs more flexibility than other languages.
PROGRAMMING DOMAINS
Web Software
To accommodate dynamic Web content, some
computation capability is often included in the
technology of content presentation.
markup (e.g., XHTML), scripting (e.g., PHP),
general-purpose (e.g., Java)
6
LANGUAGE EVALUATION CRITERIA
Readability
The ease with which programs can be read and
understood
Writability
The ease with which a language can be used to
create programs
Reliability
Conformance/conformity to specifications (i.e.,
performs to its specifications)
Cost
The ultimate total cost
7
READABILITY
Maintenance was recognized as a major part
of the software life cycle, particularly in
terms of cost.
Ease of maintenance is determined in large
part by the readability of programs.
8
READABILITY
Overall simplicity
Simple core features/constructs
Few feature multiplicity (methods of doing the
same operation)
For example, in Java, the following ways could
be used to increase an integer variable
count = count + 1
count += 1
count++
++count
Note: Simplicity improves readability;
however, excessive simplicity may also reduce
readability.
Orthogonality
Allow combination of primitive constructs of few
numbers. 9
READABILITY
Control statements
Having well-known control structures, e.g.,
while, for.
Data types and structures
The presence of adequate facilities for defining data
structures
Example:
If a language doesn’t have a Boolean type, then it may
need to use a numeric type as an indicator flag
timeOut = 1
Compared with a language providing Boolean type, the
following state is much more readable
timeOut = true
Syntax considerations
Identifier forms: flexible composition
language’s Special words 10
methods of forming compound statements – C
uses braces to specify compound statements.
LANGUAGE CONSTRUCT
A language construct is a syntactical element
provided by a programming language to enable
programmers to control the behavior and flow of a
program.
Examples of language constructs include:
Control flow constructs: These allow you to control
the flow of execution in a program.
if, else, for, while loops, and switch in many languages.
Data structure constructs: These define how data is
structured or stored.
struct, class, array, list.
Exception handling constructs: These allow a
program to manage errors or exceptions. 11
try, catch, finally.
WRITABILITY
Writability is a measure of how easily a language
can be used to create programs for a chosen
problem domain.
Simplicity and orthogonality
Few core constructs, a small number of primitives, and a
small set of rules for combining them.
Support for abstraction
The ability to define and use complex structures
or operations in ways that allow details to be
ignored
Programming languages can support two distinct
categories of abstraction:
Process - use of a subprogram several times in a
program.
Data- Any C++ program where you implement a class 12
with public and private members is an example of data
abstraction.
WRITABILITY
Expressivity
Convenient ways of specifying
operations
PASCAL, C (count++ at the place
of count=count+1)
the inclusion of for statements in
many modern languages makes
writing counting loops easier than
with the use of while.
13
RELIABILITY
Type checking
Testing for type errors, ideally on compile time, not in runtime.
Run-time type checking is expensive.
Compile-time type checking is more desirable.
The earlier errors in programs are detected, the less expensive it is
to make the required repairs.
Exception handling
Intercept run-time errors and take corrective measures, then
continue the corresponding program’s execution (C++, Java, C#).
Aliasing
Presence of two or more distinct referencing methods for
the exact memory location
It is now widely accepted that aliasing is a dangerous
feature in a programming language
Most programming languages allow some kind of aliasing –
for example, two pointers are set to point to the same 14
variable.
COST
Training programmers to use language
Writing programs
Compiling programs
Executing programs
Language implementation system:
availability of free compilers
Reliability: poor reliability leads to high costs
Maintaining programs
15
OTHERS
Portability
The ease with which programs can be moved
from one implementation to another
Generality
The applicability to a wide range of applications
Well-defined
The completeness and precision of the
language’s official definition.
16
INFLUENCES ON LANGUAGE
DESIGN
Computer Architecture
Languages are developed around the prevalent
computer architecture, known as the von
Neumann architecture
Programming Methodologies
New software development methodologies (e.g.,
object-oriented software development) led to
new programming paradigms and, by extension,
new programming languages.
17
COMPUTER ARCHITECTURE
INFLUENCE
Well-known computer architecture: Von
Neumann
Imperative languages, most dominant because
of von Neumann computers
Data and programs stored in memory
Memory is separated from the CPU
Instructions and data are piped from memory to the
CPU
Basis for imperative languages
Variables model memory cells
Assignment statements model piping
Iteration is efficient on von Neumann computers
because instructions are stored in adjacent cells of
memory, and repeating the execution of a section 18
of code requires only simple branch instructions.
PROGRAMMING METHODOLOGIES
INFLUENCES
1950s and early 1960s:
Simple applications;
worry about machine efficiency
1970s:
hardware costs decreased
programmer costs increased
computers were solving larger and more
complex problems
Emphasis:
structured programming
top-down design and step-wise refinement
Deficiency:
Incompleteness of type checking
19
PROGRAMMING METHODOLOGIES
INFLUENCES
Late 1970s:
shift from procedure-oriented to data-oriented
emphasize data design, focusing on the use of abstract data
types to solve problems
most languages designed since the late 1970s support data
abstraction
Middle 1980s: Object-oriented programming
data abstraction
encapsulates processing with data objects
controls access to data
Inheritance
enhances the potential reuse of existing software, thereby
providing the possibility of significant increases in software
development productivity
dynamic method binding
allow more flexible use of inheritance
20
overloaded method
overridden method
LANGUAGE CATEGORIES
Imperative
Focuses on how to achieve tasks by specifying a
sequence of instructions or steps that change a
program's state. Examples include C, Python, and
Java.
Functional
Emphasizes computation through mathematical
functions and avoids changing state or mutable
data. It promotes immutability and side-effect-free
functions. Examples include Haskell, Lisp, and
Scala.
Logic
Based on formal logic, where programs consist of
a set of facts and rules. The execution is about 21
proving assertions through logical inference.
Examples include Prolog and Datalog.
LANGUAGE CATEGORIES
Object-oriented
Organizes code around objects, which are
instances of classes. Objects encapsulate data
and behavior, promoting modularity and reuse.
Examples include Java, C++, and Python.
Markup
These are not programming languages in the
traditional sense, as they don't perform
computations or logic. Instead, they are used to
structure, format, and annotate documents,
particularly for web pages and data
representation. E.g., XHTML, XML.
22
LANGUAGE DESIGN TRADE-OFFS
Evaluation criteria are self-contradictory!!!
Reliability vs. cost of execution
Example: Conflicting criteria
Example: Java demands all references to array
elements be checked to ensure that the index is in
it legal ranges, but that leads to increased
execution costs
Readability vs. writability
Example: APL provides many powerful operators,
allowing complex computations to be written in a
compact program but at the cost of poor readability
Writability (flexibility) vs. reliability
Example: C++ pointers are powerful and very
flexible but unreliable, so they are not used in Java. 23
IMPLEMENTATION METHODS
Compilation
Programs are translated into machine language
Pure Interpretation
Programs are interpreted by another program
known as an interpreter
Hybrid Implementation Systems
A compromise between compilers and pure
interpreters
24
COMPILATION
Translate high-level program (source language)
into machine code (machine language)
Slow translation, fast execution
The compilation process has several phases:
Lexical analysis: converts characters in the source
program into lexical units
Syntax analysis transforms lexical units into parse
trees, which represent the syntactic structure of the
program
Semantics analysis: generate intermediate code -
translate a source program into an intermediate language
one
semantics analysis: check for errors that are difficult, if
not impossible, to detect during syntax analysis, such as
type errors. 25
code generation: machine code is generated
OPTIMIZATION THROUGH A
COMPILER
Improve programs (usually in their
intermediate code version) by making them
smaller or faster or both, is often an optional
part of compilation.
Some compilers are incapable of doing any
significant optimization.
Optimization may
omit some code in your program
change the execution order of code in your
program
P.S.: Sometimes, especially when synchronization
between processes is required, the above results
may create some bugs in your programs which
27
cannot be detected by just checking the source
code.
PURE INTERPRETATION
Source program is interpreted by another
program (interpreter) with no translation
whatsoever.
The interpreter program acts as a software
simulation of a machine whose fetch-execute
cycle deals with high-level language program
statements rather than machine instructions.
This software simulation provides a virtual
machine for the language.
Allowing easy implementation of many source-
level debugging operations because all run-time
error messages can refer to source-level units.
For example, if an array is out of range, the error
message can easily indicate the source line and the 28
array's name.
PURE INTERPRETATION
Slower execution (10 to 100 times slower
than compiled programs)
The decoding of high-level language statements
is far more complex than machine language
instruction.
Regardless of how many times a statement is
executed, it must be decoded every time.
Often requires more space.
In addition to the source program, the symbol
table must be present during interpretation
Becoming rare in high-level languages
Significant comeback with some Web
scripting languages (e.g., JavaScript, PHP) 29
30
HYBRID IMPLEMENTATION
SYSTEMS
A compromise between compilers and pure
interpreters
A high-level language program is translated to an
intermediate language that allows easy
interpretation
Faster than pure interpretation
Examples
Perl programs are partially compiled to detect errors
before interpretation to simplify the interpreter.
Initial implementations of Java were hybrid. The
intermediate form, byte code, provides portability to
any machine that has a byte code interpreter and a
run-time system (Java class library)—together, these
are called Java Virtual Machines.
There are now systems that translate Java byte code 31
into machine code for faster execution.
32
THE END
33