Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Principles of Programming

Languages
Introduction
General information

2
Lecturers
● Class hours:
○ Nguyễn Thị Minh Huyền (huyenntm@hus.edu.vn)
● Lab hours:
○ Nguyễn Thị Tâm (nguyenthitam@hus.edu.vn)
○ Nguyễn Thị Minh Huyền

3
Course Objectives
● Help students to understand the concepts behind language design, i.e. to
think about languages in terms of
○ Naming and binding
○ Data types and abstraction mechanisms
○ Control flow
○ Subroutine closures
○ Concurrency
○ ...

4
Topics
● Programming languages and compilation
○ Formal specifications (lexical, syntax, semantics)
● Names, bindings, and scopes
● Control flow
● Subroutines
● Data types
● Data abstraction and object orientation
● Functional programming
● Logic programming
● Scripting
● Concurrency (optional)

5
References
● Michael L. Scott (2016), Programming Language Pragmatics, 4th edition, Morgan Kaufmann.
● Robert W. Sebesta (2019), Concepts of Programming Languages, 12th Edition, Addison Wesley.

6
Requirements
● Textbook reading before class hours
○ Q&A at the beginning and at the end of each class
● Homeworks submitted before lab hours

7
Evaluation
● Quizzes and assignments (40%)
● Final exam (60%)

8
How to study effectively?
● Always take notes (that helps you to memorize better and to identify what
you don’t understand yet)
● Identify and revise all new concepts after each class, read further
documents if needed
● Do yourself all assignments as much as possible
● Improve your English reading comprehension skills by reading and
reading again
● Self-studying is very important

9
● Why study PPL?
● Programming domains
● Language evaluation criteria

Introduction ● Influences on language


design
Principles of programming ● Language categories
languages ● Implementation methods:
Compilation/Interpretation
● Programming environments

Notes: Slides borrowed from M. Scott and R. Sebesta


10
materials provided with their books
Why study PPL?
● There are so many programming languages
○ 688 listed on Wikipedia as of Sep. 2021
○ Evolution: constantly finding better ways to do things
○ Language design for special purposes or special hardwares
○ Personal preference: diverse ideas about what is pleasant to use
● Help you choose a language
○ Special purposes
● Make it easier to learn new languages
○ Concepts have similarities (data types, control flows, abstraction, etc)
● Help you make better use of whatever language you choose
○ Understanding of language features, implementation costs, how to do things in languages
that don’t support them explicitly

11
● Why study PLP?
● Programming domains
● Language evaluation criteria

Introduction ● Influences on language


design
Principles of programming ● Language categories
languages ● Implementation methods:
Compilation/Interpretation
● Programming environments

Notes: Slides borrowed from M. Scott and Sebesta


12
materials provided with their books
Programming domains
● Scientific applications
○ Large numbers of floating point computations; use of arrays (e.g. Fortran)
● Business applications
○ Produce reports; use decimal numbers and characters (e.g. COBOL)
● Artificial intelligence
○ Symbols rather than numbers manipulated; use of linked lists (e.g. LISP, Prolog)
● System programming
○ Need efficiency (e.g. C)
● Web programming
○ Markup (e.g. HTML/XML), scripting (e.g. PHP), general-purpose (e.g. Java) languages

13
● Why study PPL?
● Programming domains
● Language evaluation criteria

Introduction ● Influences on language


design
Principles of programming ● Language categories
languages ● Implementation methods:
Compilation/Interpretation
● Programming environments

Notes: Slides borrowed from M. Scott and Sebesta


14
materials provided with their books
Language evaluation criteria
● Readability: easy to be read and understood
○ Overall simplicity: manageable set of features and constructs, minimal feature multiplicity, minimal
operator overloading
○ Orthogonality: a relatively small set of primitive constructs can be combined in a relatively small number
of ways, every possible combination is legal
○ Adequate predefined data types
○ Syntax considerations
● Writability: easy to learn and to create programs
○ Simplicity and orthogonality; Abstraction; Expressivity
● Reliability
○ Type checking; Exception handling; Aliasing; Readability and writability
● Cost: the ultimate total cost
○ Training programmers; Writing programs; Executing programs; Reliability; Maintaining programs
● Portability: easy to move from one implementation to another
● Generality: wide range of applications
● Well-definedness

15
● Why study PPL?
● Programming domains
● Language evaluation criteria

Introduction ● Influences on language


design
Principles of programming ● Language categories
languages ● Implementation methods:
Compilation/Interpretation
● Programming environments

Notes: Slides borrowed from M. Scott and Sebesta


16
materials provided with their books
Influences on language design
● Computer architecture
○ Languages are developed around the prevalent computer architecture: von Neumann
architecture
● Program design methodologies
○ New software development methodologies led to new programming paradigms, and
consequently new programming languages

17
The von Neumann Architecture
● Well-known computer
architecture: von Neumann
○ Data and programs stored in
memory
○ Memory is separate from CPU
(Central Processing Unit)
○ Instructions and data are piped
from memory to CPU

○ Basis for imperative languages


■ Variables model memory cells
■ Assignment statements model piping
■ Iteration is efficient
18
The von Neumann Architecture
● Fetch-execute-cycle on a von Neumann architecture computer

initialize the program counter


repeat forever
fetch the instruction pointed by the counter
increment the counter
decode the instruction
execute the instruction
end repeat

19
Programming methodologies
● 1950s and early 1960s: Simple applications, worry about machine
efficiency
● Late 1960s: People efficiency became important; readability, better
control structures
○ Structured programming
○ Top-down design and stepwise refinement
● Late 1970s: Process-oriented to data-oriented
○ Data abstraction
● Middle 1980s: Object-oriented programming
○ Data abstraction + inheritance + polymorphism

20
● Why study PPL?
● Programming domains
● Language evaluation criteria

Introduction ● Influences on language


design
Principles of programming ● Language categories
languages ● Implementation methods:
Compilation/Interpretation
● Programming environments

Notes: Slides borrowed from M. Scott and Sebesta


21
materials provided with their books
Language categories
● Imperative languages
○ von Neumann based languages with central features being variables, assignment
statements, and iteration (e.g. Fortran, Pascal, Basic, C)
○ Object-oriented languages (e.g. Smalltalk, Eiffel, C++, Java)
○ Scripting languages (e.g. Perl, Python, JavaScript, PHP)
○ Visual languages (e.g. Visual Basic .NET)
● Declarative languages
○ Functional: main means of making computations is by applying functions to given
parameters (e.g. LISP, Scheme, ML, F#, Haskell)
○ Logic, constraint-based: Rule-based programming, in which rules are specified in no
particular order (e.g. Prolog, VisiCalc, RPG)

22
● Why study PPL?
● Programming domains
● Language evaluation criteria

Introduction ● Influences on language


design
Principles of programming ● Language categories
languages ● Implementation methods:
Compilation/Interpretation
● Programming environments

Notes: Slides borrowed from M. Scott and Sebesta


23
materials provided with their books
Implementation methods: Compilation vs. Interpretation
● Compilation vs. interpretation: not opposites, not a clear-cut distinction
● Pure compilation
○ The compiler translates the high-level source program into an equivalent target program
(typically in machine language), and then goes away

● Pure Interpretation
○ Interpreter stays around for the execution of the program, being the locus of control
during execution

24
Compilation vs. Interpretation
● Compilation vs. Interpretation
○ Interpretation: greater flexibility, better diagnostics (error messages)
○ Compilation: better performance (10 to 100 times faster, less space)
● Common case is compilation or simple pre-processing, followed by
interpretation
○ Most language implementations include a mixture of both compilation and interpretation

25
Layered view of computer
● The operating system and
language implementation are
layered over machine interface
of a computer

26
Additional terminologies
● Additional components for compilation
○ Load module
○ Linking and loading: collecting system program units and linking them to a user program
● Von Neumann bottleneck
○ Program instructions often can be executed much faster than the speed of the connection (between a
computer’s memory and its processor); the connection speed thus results in a bottleneck
● Just-in-Time (JIT) implementation systems: delayed compilers
○ Initially translate programs to an intermediate language
○ Then compile the intermediate language of the subprograms into machine code when they are called.
These machine code versions are kept for subsequent calls
○ Widely used for Java programs, .NET languages
● Preprocessors
○ Processes a program immediately before the program is compiled to expand embedded preprocessor
macros
○ E.g. C preprocessors expands #include, #define and similar macros (preprocessor instructions)

27
● Why study PPL?
● Programming domains
● Language evaluation criteria

Introduction ● Influences on language


design
Principles of programming ● Language categories
languages ● Implementation methods:
Compilation/Interpretation
● Programming environments

Notes: Slides borrowed from M. Scott and Sebesta


28
materials provided with their books
Programming environments
● A collection of tools used in software development, e.g.,
○ Microsoft Visual Studio.NET
○ NetBeans
○ Eclipse

29
● What are the most important criteria for evaluating
programming languages?
● What is the difference between machine language

Questions ●
and assembly language?
What distinguishes declarative languages from
imperative languages?
● Explain the distinction between interpretation and
compilation. What are the comparative advantages
and disadvantages of the two approaches?
● What is the difference between a compiler and a
preprocessor?

30
● Write programs to find the
greatest common divisor of

Assignments two numbers in 6 different


programming languages at
Programming assignments your choice, including at least
one functional language and
one logic language.

31
● Read the overview of
compilation (Scott book,
section 1.6)

Next course ● Watch this video on lexical


analysis
Preparation assignments https://www.youtube.com/wa
tch?v=L-il96czPGc&list=PLK06
XT3hFPzjCtPI9gufwId_22i1BEZ
vT&index=2

32

You might also like