1 / 20

03-60-440 Principles of Programming Languages (2011F)

03-60-440 Principles of Programming Languages (2011F). 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

Download Presentation

03-60-440 Principles of Programming Languages (2011F)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 03-60-440Principles of Programming Languages (2011F) Jianguo Lu School of Computer Science University of Windsor Jlu at uwindsor

  2. 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 …

  3. It is about the fundamental question • What is a programming language?

  4. 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 • …

  5. 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, …

  6. Language description: Axiomatic Semantics • Language description: Syntax (covered in 03-60-214), semantics. • Formal methods to describe semantics: operational, denotational, axiomatic … • Axiomatic semantics is also used to prove the correctness of programs • Java has Assertion to describe the meaning of program • Axiomatic semantics uses a formal system (axiomatic system) to describe the meaning of programs • For example, {x=0} x= x+1; y= x; { x=1AND y=1} Axiom Inference rule

  7. 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 (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; } } insertionSort

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

  9. 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: funinsertsort [] = [] | 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;

  10. 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)))))

  11. 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).

  12. OOP • Abstract Data Type • Multiple inheritance in Java • Polymorphism • Overloading • Generics • Dynamic binding

  13. Distributed Object and Object Persistency from www.agiledata.org

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

  15. void transfer(Account fromAccount, Account toAccount, int amount) { if (!getCurrentUser().canPerform(OP_TRANSFER)) { throw new SecurityException(); } if (fromAccount.getBalance() < amount) { throw new InsufficientFundsException(); } Transaction tx = database.newTransaction(); try { fromAccount.withdraw(amount); toAcount.deposit(amount); tx.commit(); systemLog.logOperation(OP_TRANSFER, fromAccount, toAccount, amount); } catch(Exception e) { tx.rollback(); } } The code has lost its elegance and simplicity various new concerns tangled with the basic functionality (business logic concern). The transactions, security, logging, etc. all exemplify cross-cutting concerns. Implementation of crosscutting concerns are scattered across numerous methods. Change of the implementation would require a major effort. Solution: Separate different concerns. Aspect Oriented Programming

  16. XSLT XSLT processor XML 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.

  17. Robert Sabastia, Von Roy &Haridi, John Mitchell, Benjemin Pierce, Glynn Winskel, Kenneth Louden, Seyed Roosta, Pratt & Zelkowitz

  18. Times and places • Course web site: http://cs.uwindsor.ca/~jlu/440 • Office: 5111 Lambton Tower • Email: jlu at uwindsor • Office hours: Tuesday & Thursday 2:30-3:30 • Midterms: October 20, in class time • Final exam:  December 15, 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.

  19. Grade

  20. 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.

More Related