Upload
others
View
9
Download
0
Embed Size (px)
Citation preview
April 14, 2020 Sam Siewert
CS 332Programming Language Concepts
Lecture 14 – REVIEW(PLP Chapters 8-12)
Exam #2 on Canvas 4/22-4/242 hours to complete, 1 attempt, no outside expert help– Open book, open notes ok– If you re-use any code or material from Internet be sure to cite and
explain
Exam #1, #2, worth at most 15% of grade each [30% total]
Assignment practice, participation and scaffold is 40%
Final Exam worth 20% or more [presentation, Ex #6 report]
Participation Based on Attendance and Final Exam Attendance (Q&A for other groups)
Overall policies – Active Learning Grading Policy
Sam Siewert 2
Final Presentation ZOOMStandard Exam Time Presentation option
Overflow Presentation time
Sam Siewert 3
Register for ZOOM
STANDARD EXAM TIMEALTERNATE TIME
Schedule Coming Soon!
Major ConceptsCore Language Design ------------------------------------------Subroutines and Parameter Passing – Ch. 8– See Modes on P. 404
1. Value2. Reference3. Closure
Data Abstraction and OO – Ch. 9– What is Required for an OOP (P. 449)– Parametric and Class Instance Dynamic Binding with Inheritance
Alternative Programming Models ----------------------------Functional Languages – Ch. 10– Lisp and Scheme
Logic Languages (PROLOG) – Ch. 11Concurrency Built-in or Library – Ch. 12
Sam Siewert 4
Core Language Design
Subroutinesand
Object Oriented Programming
Sam Siewert
5
PLP Ch. 8Subroutine Calls and Parameter Passing– call by value: copy going into the procedure– call by result: copy going out of the procedure– call by value result: copy going in, and again going out– call by reference: pass a pointer to the actual parameter, and
indirect through the pointer – call by name: re-evaluate the actual parameter on every use.
For actual parameters that are simple variables, this is the same as call by reference. For actual parameters that are expressions, the expression is re-evaluated on each access. It should be a runtime error to assign into a formal parameter passed by name, if the actual parameter is an expression.
– Closure (just read and understand concept of enclosing context with function call)
Sam Siewert 6
Parameter Passing - for Well-Known PLsAda - in (by value), out (by result), in/out (by value/result)– Optimization for records
and arrays (reference)
C by value only
C++ reference added
FORTRAN - generally by reference only
Java - by value AND by reference– built-in by value– Class by shared reference
Sam Siewert 7
1. UW CS examples2. FSU notes
PLP Ch. 8Nested subroutines – what is value?
Generic, Template and Pre-processed (Text Substitution) for Parametric Instances– Avoid Duplicate Algorithms to Operate on Different Types– Parametric Polymorphism
Generics and Templates in C++ and Java – Why?
Why is Function/Procedure Nesting Going Away in Imperative Procedural Languages? Or is it?– http://stackoverflow.com/questions/9438874/using-lambdas-to-do-
nested-functions– http://stackoverflow.com/questions/8070811/does-c11-have-any-
support-for-local-functions
Asynchronous Exceptions and Events - Concepts
Sam Siewert 8
PLP Ch. 9OO Concepts and Requirements for OOP to be OO
1. Classes2. Interfaces, Encapsulation, Public and Private 3. Parametric Polymorphism and True Polymorphism with
Inheritance and Late Binding4. Constructors and Destructors5. Dynamic Method Binding and Class Refinement, Virtual
and Pure Virtual Functions for Abstract and Derived Classes
6. Multiple Inheritance (Is it Necessary?)
Sam Siewert 9
Alternative Programming Models
Functional,LogicAnd
Concurrency
Sam Siewert
10
PLP Ch. 10What Makes Functional Programming Different
Lisp and Scheme– Key Differences– Familiarity with Expressions– Let and Let*– Lambda Functions– Recursion– Example Code from Class
Lambda Calculus and History – Mathematical and Theoretical Background
Lazy Evaluation – Defer Evaluation as Long as Possible Compared to Eager or Strict Evaluation (More Common In Imperative Procedural Programming)
Sam Siewert 11
PLP Ch. 11Logic Programming
PROLOG PL – History and Uses
PROLOG Examples from Class
Horn Clauses
Facts and Rules
Forward Chaining and Backward Chaining
Tracing
Sam Siewert 12
PLP Ch. 12Concurrency Types– Non-deterministic (Simple, e.g. Multi-programming)– Fair (Scale Out)– Predictable to Deterministic (Real-Time)
Concurrency as Language Feature– Java Concurrency– Ada Tasking
Concurrency as a Library Feature and OS Feature
Concurrency Challenges– Deadlock and Livelock– Producer/Consumer– Atomic Operations and Message Queues– Priority Inversion (Can it Occur on a Fair Scheduler System?)
Sam Siewert 13
Hints …
Study Java, C++, Lisp and Scheme Code Examples Presented in Class and Posted
Make sure you Have Used Lisp and Scheme and Tested and Understood all Example Expressions and Functions
Make sure you Have Used Prolog and Tested and Understood all Example Databases
Make Sure You have read PLP with Emphasis on What Was Discussed in Class
You Can Bring 2-Sided Note Page to the Exam
Format is Same as Exam #1
Sam Siewert 14
Take-AwaysStudying PL Organization – Syntax, Semantics and Design Has Value Because
1. Makes You a Better Programmer (more insight) - Understanding how Interpreters and Compilers are Implemented
2. Many Products that Scale Out or Up, Can use Command Lines and Scripting for Automation (E.g. Update OS Configuration Files on Every Server in Datacenter) – Built into Solution
3. Every Project must SELECT a Programming Language (Selection Driven by Advantages/Disadvantages and Problem Domain fit to PL Paradigm)
Syntax Almost Always in BNF Formal Specification, E.g. Ada95, C++• Compiler or Interpreter Front-end (Flex and Bison – Spec to Implementation)• Semantics Requires Code Generation (Compiler) or Interpretation
Programming Language Specifications (Reference, Manual, Formal)
1. Semantics Sometimes by Reference, in LRM, but also Formal2. Reference Implementation [Error Prone], but with Formal BNF [Better], E.g. GCC for C and C++3. Language Reference Manual [Better], E.g. Ada83, Ada95, C++, Java4. Formal Specification [Best – E.g. Denotational Semantics – RD Tennent, Operational Semantics,
Axiomatic Semantics]• E.g. Scheme R5RS, R6RS Denotational Semantics• Ada83 – “Towards a Formal Description of Ada”, Lecture Notes in Computer Science, 1980.• C Denotational Semantics – “Denotational Semantics of ANSI C”, Nikolaos S. Papaspyrou,
Computer Standards and Interfaces, 2000.• Java Denotational Semantics – “Dynamic Denotational Semantics of Java”, Jim Alves-Foss
and Fong Shing Lam, Lecture Notes in Computer Science, 1998.
Sam Siewert 15