03-60-440_ Concepts of Programming Languages - PowerPoint - PowerPoint by hcj


Principles of Programming Languages (2010F)

                  Jianguo Lu
            School of Computer Science
               University of Windsor
                  Jlu at uwindsor
It is about programming languages…

• This course involves several programming languages:
   – Scheme (Functional)
   – Prolog (Logic)
   – AspectJ
   – XSLT

• This course is more than excursions to various languages

It is about the fundamental question

• What is a programming language?

What is a program

• It is a sequence of
   – Imperative paradigm

• It is a group of interacting
   – OO paradigm

• It is a function!
   – Functional paradigm

• It is a set of rules!
   – Logic paradigm

It is about classification, history, styles (paradigms),
concepts common in many languages
• Programming language classification and history
• Syntax and semantics of programming languages
   – Syntax is covered in 60-214. Won’t repeat it.
   – Axiomatic semantics
• Paradigms of programming
   – Imperative and declarative programming
   – OOP: Abstract data type, inheritance, polymorphism, AOP (Aspect
     Oriented Programming)
   – Functional programming, lambda calculus, Scheme, MapReduce
   – XML Programming: XSLT
   – Logic programming
• Concepts in programming languages
   – Side-effect, type checking, strong typing, overload, override, coercion, call-
     by-value, call-by-reference, polymorphism, multiple inheritance, generics,
     dynamic binding, imperative and declarative programming, …

Language description: Axiomatic Semantics
• Language description: Syntax
  (covered in 03-60-214), semantics.
• Formal methods to describe
  semantics: operational,
  denotational, axiomatic …                 Axiom
• Axiomatic semantics is also used to
  prove the correctness of programs
                                             {P(E/x)} x  E {P}
    – Java has Assertion to describe the
      meaning of program

• Axiomatic semantics uses a formal
  system (axiomatic system) to              Inference rule
  describe the meaning of programs
• For example,                             {P1} S1 {P2}, {P2} S2 {P3}
                                               {P1} S1; S2 {P3}
     x= x+1;
     y= x;
    { x=1AND y=1}

Imperative programming
• Describes computation in terms of a program state and statements that change the
  program state.
• Imperative programs are a sequence of commands for the computer to perform.
• The hardware implementation of almost all computers is imperative.
• In contrast to declarative programming

    Insertion sort in Java
    void insertionSort (int[ ] A) {
      int j;
      for (int i = 1; i < A.length; i++) {
          int a = A[i];
          for (j = i -1; j >=0 && A[j] > a; j- -)
                         A[j + 1] = A[j];
          A[j + 1] = a;

Functional Programming
• Functional programming treats computation as the evaluation of
  mathematical functions.
• It is more heavily used in academia than in industry.
• The strength of a functional paradigm is the removal of side-effects
  during computation. This has uses in
    – program verification, for checking the correctness of programs,
    – program optimisation. One particular use in program optimisation is to
      transform programs for parallel programming.
    – The idea is used by google etc.

    z = f(sqrt(2), sqrt(2));
    we can factor out sqrt(2) and write
      s = sqrt(2);
      z = f(s, s);

Functional Programming vs. Imperative Programming
• In strict functional programming, there is no explicit
 memory allocation and no explicit variable assignment, so
 side effects of function evaluation are eliminated.
• Looping is accomplished through the more general
 functional construct of recursion.
   Sort in ML:
   fun insertsort [] = []
     | insertsort (x::xs) =
          let fun insert (x:real, []) = [x]
                | insert (x:real, y::ys) = if x<=y then x::y::ys
                                                  else y::insert(x, ys)
          in insert(x, insertsort xs)

sort function defined in Scheme language
(define (insert x l)
     ( if (null? l)
       (list x)
       (if (<= x (car l))
        (cons x l)
        (cons (car l) (insert x (cdr l))))))

(define (isort l)
     (if (null? l)
        (insert (car l) (isort (cdr l)))))

Logic Programming
•   Program is a set of facts and rules.
•   Based on first-order predicate logic
•   Original motivation: study of mechanical theorem proving
•   Used in Artificial Intelligence, databases, expert systems.
• Insertion sort in prolog
     isort([ ],[ ]).

     isort([X|UnSorted],AllSorted) :-

     insert(X, [ ], [X]).
     insert(X, [Y|L], [X, Y|L]) :- X =< Y.
     insert(X, [Y|L], [Y|IL]) :- X > Y, insert(X, L, IL).


• Abstract Data Type
• Multiple inheritance in Java
• Polymorphism
   – Overloading
   – Generics
   – Dynamic binding

Distributed Object and Object Persistency

                             from www.agiledata.org
AOP—Aspect Oriented Programming
• A new programming paradigm
• Example
    void transfer(Account fromAccount, Account toAccount, int amount) {
        if (fromAccount.getBalance() < amount) {
            throw new InsufficientFundsException();

• However, in a real-world banking application, this transfer method is not
  adequate. We need to:
    – Include security checks to verify that the current user has the authorization to
      perform this operation.
    – Enclose the operation in a database transaction in order to prevent accidental data
    – Log the operation to the system log. And so on.

    Aspect Oriented Programming
void transfer(Account fromAccount, Account toAccount,
     int amount) {
                                                        • The code has lost its elegance
 if (!getCurrentUser().canPerform(OP_TRANSFER)) {         and simplicity
   throw new SecurityException();
 }                                                          – various new concerns tangled
    if (fromAccount.getBalance() < amount) {                  with the basic functionality
      throw new InsufficientFundsException();                 (business logic concern).

    Transaction tx = database.newTransaction();
                                                            – The transactions, security,
    try {                                                     logging, etc. all exemplify cross-
                                                              cutting concerns.
       fromAccount, toAccount, amount);
                                                        • Implementation of crosscutting
    }                                                     concerns are scattered across
    catch(Exception e) {
                                                          numerous methods.
}                                                           – Change of the implementation
                                                              would require a major effort.

                                                        • Solution: Separate different

• It is an XML-based language
    – Used to transform XML;
    – The language itself is in XML.

• It is a declarative language
    – Does not list an imperative sequence of actions to perform in a
      stateful environment,
    – Consists of a template rules, specifies what to add to the result.


Robert Sabastia, Von Roy &Haridi, John Mitchell, Benjemin Pierce, Glynn Winskel,
Kenneth Louden, Seyed Roosta, Pratt & Zelkowitz
Times and places
• Course web site: http://cs.uwindsor.ca/~jlu/440
• Office: 5111 Lambton Tower
• Email: jlu at uwindsor
• Office hours: Tuesday & Thursday 11:00-12:00
• Midterms: October 28, in class time
• Final exam: December 14, 15:30

• Examinations are closed books and closed notes.
• The only valid excuse for missing an exam is a documented medical
  emergency. A missed exam without medical documentation will result
  in a mark of zero.


           assignments        15 %
           Midterm            35 %
           Final exam         50 %

0%   50%    53%   57%   60%   63%   67%   70%   73%   77%   80%   86%   93%
F    D-     D     D+    C-    C     C+    B-    B     B+    A-    A     A+

• Three assignments (15 %):
   – Aspect oriented programming;
   – Functional and Logic programming;
   – XSLT programming.

• TA will help you with your assignments

• There is no text book.

• Class attendance is important !
• Exams will cover whatever is taught in class;
• Exams will cover the assignments.


To top