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

VIEWS: 23 PAGES: 20

									                   03-60-440
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
 …




                                                             1
It is about the fundamental question

• What is a programming language?




                                       2
What is a program

• It is a sequence of
  statements!
   – Imperative paradigm

• It is a group of interacting
  objects!
   – OO paradigm

• It is a function!
   – Functional paradigm

• It is a set of rules!
   – Logic paradigm

•…
                                 3
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, …


                                                                                  4
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}
    {x=0}
                                               {P1} S1; S2 {P3}
     x= x+1;
     y= x;
    { x=1AND y=1}



                                                                        5
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;
       }
    }




                                                                                     6
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);


                                                                               7
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)
   end;

                                                                          8
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)))))


                                               9
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) :-
        isort(UnSorted,Sorted),
        insert(X,Sorted,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).


                                                                  10
OOP

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




                                 11
Distributed Object and Object Persistency




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

• 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
      loss.
    – Log the operation to the system log. And so on.


                                                                                         13
    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-
      fromAccount.withdraw(amount);
      toAcount.deposit(amount);
                                                              cutting concerns.
      tx.commit();
      systemLog.logOperation(OP_TRANSFER,
       fromAccount, toAccount, amount);
                                                        • Implementation of crosscutting
    }                                                     concerns are scattered across
    catch(Exception e) {
      tx.rollback();
                                                          numerous methods.
    }
}                                                           – Change of the implementation
                                                              would require a major effort.

                                                        • Solution: Separate different
                                                          concerns.

                                                                                              14
XSLT
• 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.

                                                   XSLT




                                                     XSLT
                                                   processor
                                  XML
                                                                           15
Robert Sabastia, Von Roy &Haridi, John Mitchell, Benjemin Pierce, Glynn Winskel,
Kenneth Louden, Seyed Roosta, Pratt & Zelkowitz
                                                                             16
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.

                                                                      17
Grade


           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+




                                                                        18
• 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.

                                                  19

								
To top