0% found this document useful (0 votes)
60 views44 pages

CSC304 Week 1 Slides

Uploaded by

Adebimpe Adetoba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views44 pages

CSC304 Week 1 Slides

Uploaded by

Adebimpe Adetoba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

CSC304:

Survey of Programming Languages

WEEK ONE: Introduction

Kingsley Chiwuike Ukaoha, PhD


INTRODUCTION
• Getting to Know each other
– My name…Kingsley Chiwuike Ukaoha
– Your names….. Seat by seat
• Class Etiquettes (if any)…..
• Your expectations from Me..
• My expectations from You….
• Feedback Mechanisms
COURSE DESCRIPTION
• Four hours weekly (4 Units course)
• Mondays 2.00pm – 4.00pm &
• Tuesdays 9:00am-11:00am
• Materials to use are:
– Sebesta, R. W. (2011). Concepts of Programming
Languages. Tenth Edition, University of Colorado at
Colorado Spring Pearson.

– Tucker, A. B. (2007). Programming Languages: Principles


and Paradigms, Tata Mcgraw-Hill Publishing Company
Limited; ISBN, 0070487049, 9780070487048 .
COURSE DESCRIPTION
• The course is designed to describe the
fundamental concepts of programming language
by discussing
– the design issues of the various language
constructs,
– examining the design choices for these
constructs in some common languages,
– and critically comparing design alternatives,
– Fundamental syntactic and semantic concepts
underlying modern programming languages,
COURSE DESCRIPTION
• Different modern programming languages:
– C/C++, C#, Java, Python, LISP, PERL, ALGOL and
PROLOG,
– their syntax: bindings and scope,
– data types and type checking,
– functional scheme,
– expression of assignments,
– control structure,
– program statements, program units etc., and
• finally language comparison.
OBJECTIVES
– Explain the benefits of intermediate languages in the
compilation process
– Evaluate the tradeoffs in reliability vs. writability.
– Compare and contrast compiled and interpreted execution
models, outlining the relative merits of each.
– Describe the phases of program translation from source code
to executable code and the files produced by these phases.
– Explain the differences between machine-dependent and
machine-independent translation and where these
differences are evident in the translation process.
– Explain formal methods of describing syntax (backus-naur
form, context-free grammars, and parser tree).
– Describe the meanings of programs (dynamic semantics,
weakest precondition)
OBJECTIVES
– Identify and describe the properties of a variable such as
its associated address, value, scope, persistence, and size
– Explain data types: primitive types, character string
types, user-defined ordinal types, array types, associative
arrays, point and reference types
– Demonstrate different forms of binding, visibility,
scoping, and lifetime management.
– Demonstrate the difference between overridden and
overloaded subprograms
– Explain functional side effects.
– Demonstrate the difference between pass-by-value,
pass-by-result, pass-by-value-result, pass-by-reference,
and pass-by-name parameter passing.
OBJECTIVES
– Explain the difference between the static binding and
dynamic binding.
– Discuss evolution, history, program structure and
features of some commonly used programming
languages paradigm such as C/C++, C#, Java, Python,
LISP, PERL, ALGOL and PROLOG.
– Examine, evaluate and compare these languages
– To increase capacity of computer science students to
express ideas
– Improve their background for choosing appropriate
languages
– Increase the ability to learn new languages
– To better understand the significance of programming
implementation
– Overall advancement of computing.
INTRODUCTION
• Since the invention of the Difference Engine in
1822,
• Computers have required a means of instructing
them to perform a specific task.
• This means is known as a programming language.
• Computer languages were first composed of a
series of steps to wire a particular program;
• these morphed into a series of steps keyed into
the computer and then executed;
• later these languages acquired advanced features
such as logical branching and object orientation.
INTRODUCTION
• The computer languages of the last fifty years
have come in two stages,
– the first major languages and
– the second major languages, which are in use today.
• Most computer programming languages were
inspired by or built upon concepts from
previous computer programming languages.
• Today, while older languages still serve as a
strong foundation for new ones, newer
computer programming languages make
programmers‘ work simpler.
INTRODUCTION
• Businesses rely heavily on programs to meet all
of their data, transaction, and customer service
needs.
• Science and medicine need accurate and
complex programs for their research.
• Mobile applications must be updated to meet
consumer demands.
• And all of these new and growing needs ensure
that computer programming languages, both
old and new, will remain an important part of
modern life.
Programming Language
• A programming language is an artificial
language designed to express computations or
algorithms that can be performed by a
computer -- Wikipedia
• A program is computer coding of
an algorithm that Input
– Takes input
– Performs some calculations on Program
the input
– Generates output
Output
Models of Programming Languages

Programming is like …
1st View: Imperative & Procedural
• Computers take commands and do operations
• Thus, programming is like …
issuing procedural commands to the computer
– Example: a factorial function in C
int fact(int n) {
int sofar = 1;
while (n>0) sofar *= n--;
return sofar;
}
• Since almost all computers today use the von
Neumann architecture → PL mimic the
architecture.
The von Neumann Architecture

Program counter

(Fig. 1.1)
The von Neumann Architecture
• Key features:
– Data and programs stored in memory
– Instructions and data are piped from memory to
CPU
– Fetch-execute-cycle for each machine instruction
initialize the program counter (PC)
repeat forever
fetch the instruction pointed by PC
add A,B,C 0100 1001
increment the counter
sub C,D,E 0110 1010
decode the instruction br LOOP 1011 0110
execute the instruction … …
end repeat Assembly Machine
code code
Imperative Language and Architecture
• Example: a factorial function in C
int fact(int n) {
int sofar = 1;
while (n>0) sofar *= n--;
return sofar;
}
– Indicates that data n,
sofar, and program code
are stored in memory
– Program code instructs
CPU to do operations
Imperative Language and Architecture

sofar
n

int fact(int n) {
int sofar = 1;
while (n>0) sofar *= n--;
return sofar; }

Program counter
Imperative Languages
• Imperative languages, e.g., C, C++, Java, which
dominate programming, mimic von Neumann
architecture
– Variables → memory cells
– Assignment statements → data piping between
memory and CPU
– Operations and expressions → CPU executions
– Explicit control of execution flows → prog. counter
• Allow efficient mapping between language and
hardware for good execution performance, but
limited by von Neumann bottleneck
Layers of Abstraction/Translation
High Level Language temp = v[k];
Program
v[k] = v[k+1];
Compiler v[k+1] = temp;
Assembly Language lw $15, 0($2)
Program
lw $16, 4($2)
Assembler sw$16, 0($2)
sw$15, 4($2)
Machine Language 0000 1001 1100 0110 1010 1111 0101 1000
Program 1010 1111 0101 1000 0000 1001 1100 0110
1100 0110 1010 1111 0101 1000 0000 1001
0101 1000 0000 1001 1100 0110 1010 1111
Machine
Interpretation
All imperative!
Control Signal
Specification
ALUOP[0:3] <= InstReg[9:11] & MASK
2nd View: Functional
• Programming is like …
solving mathematical functions, e.g.,
z = f(y, g(h(x)))
– A program, and its subprograms, are just
implementations of mathematical functions
– Example: a factorial function in ML
fun fact x = Input Input
if x <= 0
then 1
else x * fact(x-1); Program Function

Output Output
Another Functional Language: LISP
• Example: a factorial function in Lisp
(defun fact (x)
(if (<= x 0) 1 (* x (fact (- x 1)))))
– Computations by applying functions to parameters
– No concept of variables (storage) or assignment
• Single-valued variables: no assignment, not storage
– Control via recursion and conditional expressions
• Branches → conditional expressions
• Iterations → recursion
– Dynamically allocated linked lists
• 2nd-oldest general-purpose PL still in use (1958)
3rd View: Logic
• Programming is like …
logic induction
– Program expressed as rules in formal logic
– Execution by rule resolution
– Example: relationship among people

fact: mother(joanne,jake).
father(vern,joanne).
rule: grandparent(X,Z) :- parent(X,Y),
parent(Y,Z).
goal: grandparent(vern,jake).
Logic Programming
• Non-procedural
– Only supply relevant facts (predicate calculus) and
inference rules (resolutions)
– System then infer the truth of given queries/goals
• Highly inefficient, small application areas
(database, AI)
– Example: a factorial function in Prolog
fact(X,1) :- X =:= 1.
fact(X,Fact) :-
X > 1, NewX is X - 1,
fact(NewX,NF),
Fact is X * NF.
Summary: Language Categories

Imperative Functional
Logic Language
Language Language

Memory

ALU Control

von Neumann Architecture


Summary: Language Categories
• Imperative
– Variables, assignment statements, and iteration
– Include languages that support object-oriented
programming, scripting languages, visual languages
– Ex.: C, Java, Perl, JavaScript, Visual BASIC .NET
• Functional
– Computing by applying functions to given parameters
– Ex.: LISP, Scheme, ML
• Logic
– Rule-based (rules are specified in no particular order)
– Ex.: Prolog
Programming Design Methodology
• 1950s and early 1960s: simple applications; worry
about machine efficiency (FORTRAN)
• Late 1960s: people efficiency important;
readability, better control structures (ALGOL)
– Structured programming, free format lexical
– Top-down design and step-wise refinement
• Late 1970s: process-oriented to data-oriented
– Data abstraction
• Middle 1980s: object-oriented programming
– Data abstraction + inheritance + dynamic binding
Genealogy
of Common
Languages
What Make a Good PL?
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: a program performs to its
specifications under all conditions
• Cost
Features Related to Readability
• Overall simplicity: lang. is more readable if
– Fewer features and basic constructs
• Readability problems occur whenever program’s author
uses a subset different from that familiar to reader
– Fewer feature multiplicity (i.e., doing the same
operation with different ways)
– Minimal operator overloading
• Orthogonality
– A relatively small set of primitive constructs can be
combined in a relatively small number of ways
– Every combination is legal, independent of context
➔ Few exceptions, irregularities
Features Related to Readability
• Control statements
– Sufficient control statements for structured prog.
→ can read program from top to bottom w/o jump
• Data types and structures
– Adequate facilities for defining data type & structure
• Syntax considerations
– Identifier forms: flexible composition
– Special words and methods of forming compound
statements
– Form and meaning: self-descriptive constructs,
meaningful keywords
Writability
• Simplicity and orthogonality
– But, too orthogonal may cause errors undetected
• Support for abstraction
– Ability to define and use complex structures or
operations in ways that allow details to be ignored
– Abstraction in process (e.g. subprogram), data
• Expressivity
– A set of relatively convenient ways of specifying
operations
– Example: the inclusion of for statement in many
modern languages
Reliability
• Type checking
– Testing for type errors, e.g. subprogram parameters
• Exception handling
– Intercept run-time errors & take corrective measures
• Aliasing
– Presence of two or more distinct referencing methods
for the same memory location
• Readability and writability
– A language that does not support “natural” ways of
expressing an algorithm will necessarily use
“unnatural” approaches, and hence reduced reliability
Cost
• Training programmers to use language
• Writing programs (closeness to particular
applications)
• Compiling programs
• Executing programs: run-time type checking
• Language implementation system: availability of
free compilers
• Reliability: poor reliability leads to high costs
• Maintaining programs
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-definedness
– The completeness and precision of the language’s
official definition
• Power efficiency?
Language Design Trade-Offs
• Reliability vs. cost of execution
– e.g., Java demands all references to array elements be
checked for proper indexing but that leads to
increased execution costs
• Readability vs. writability
– e.g., APL provides many powerful operators (and a
large number of new symbols), allowing complex
computations to be written in a compact program but
at the cost of poor readability
• Writability (flexibility) vs. reliability
– e.g., C++ pointers are powerful and very flexible but
not reliably used
Implementations of PL
• It is important to understand how features and
constructs of a programming language, e.g.,
subroutine calls, are implemented
– Implementation of a PL construct means its
realization in a lower-level language, e.g. assembly
→ mapping/translation from a high-level language to
a low-level language
– Why the need to know implementations?
Understand whether a construct may be
implemented efficiently, know different
implementation methods and their tradeoffs, etc.
Implementation by Compilation
• Translate a high-level program into equivalent
machine code automatically by another program
(compiler)
• 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 syntactic structure of program
– Semantics analysis: generate intermediate code
– Code generation: machine code is generated
– Link and load
Compilation Process
(Fig. 1.3)
Implementation by Interpretation
• Program interpreted by another program
(interpreter) without translation
– Interpreter acts a simulator or virtual machine
• Easier implementation of programs (run-time
errors can easily and immediately displayed)
• Slower execution (10 to 100 times slower than
compiled programs)
• Often requires more space
• Popular with some Web scripting languages (e.g.,
JavaScript)
Hybrid Implementation Systems
• A high-level language program is translated to an
intermediate language that allows easy
interpretation
– Faster than pure interpretation
Summary
• Most important criteria for evaluating
programming languages include:
– Readability, writability, reliability, cost
• Major influences on language design have been
application domains, machine architecture and
software development methodologies
• The major methods of implementing
programming languages are: compilation, pure
interpretation, and hybrid implementation
Conclusion/ Class Activities
i. Why do you think programming is an important
task in computing?
ii. Why do we have so many programming
languages?
iii. Why are we not using just one major programming
language for all our computing tasks?
iv. Between Compilation and Interpretation, which is
better and which is faster?
v. When are Compilers used and when are
Interpreters used?
Conclusion/ Class Activities
i. Why is it useful for a programmer to have some
background in language design, even though he or she
may never actually design a programming language?
ii. How can knowledge of programming language
characteristics benefit the whole computing
community?
iii. What arguments can you make for the idea of a single
language for all programming domains?
iv. What arguments can you make against the idea of a
single language for all programming domains?

You might also like