Extracts from the upcoming book « Concepts, Techniques, and Models of Computer Programming » June 18, 2001 Workshop on Multiparadigm Programming with OO.

Slides:



Advertisements
Similar presentations
ARCHITECTURES FOR ARTIFICIAL INTELLIGENCE SYSTEMS
Advertisements

C. Varela; Adapted from S. Haridi and P. Van Roy1 Declarative Programming Techniques Lazy Execution (VRH 4.5) Carlos Varela RPI Adapted with permission.
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model From kernel to practical language (CTM 2.6) Exceptions (CTM.
© 2006 ITT Educational Services Inc. SE350 System Analysis for Software Engineers: Unit 9 Slide 1 Appendix 3 Object-Oriented Analysis and Design.
© 2002 P. Van Roy and S. Haridi 1 Teaching Programming Broadly and Deeply: The Kernel Language Approach July 11, 2002 IFIP WG3.2 Working Conference on.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
1 Introducing Collaboration to Single User Applications A Survey and Analysis of Recent Work by Brian Cornell For Collaborative Systems Fall 2006.
C. Varela; Adapted with permission from S. Haridi and P. Van Roy1 Oz, Declarative Concurrency, and Active Objects (VRH 4, 7.8) Carlos Varela RPI Adapted.
C. Varela; Adapted w. permission from S. Haridi and P. Van Roy1 Introduction to Programming Concepts Carlos Varela RPI Adapted with permission from: Seif.
Concurrency CS 510: Programming Languages David Walker.
Review of “Embedded Software” by E.A. Lee Katherine Barrow Vladimir Jakobac.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
C. Varela; Adapted from S. Haridi and P. Van Roy1 Object-Oriented Programming Active Objects (VRH 7.8) Carlos Varela RPI Adapted with permission from:
1 Static vs dynamic SAGAs Ivan Lanese Computer Science Department University of Bologna/INRIA Italy.
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
Kendall & KendallCopyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall 9 Kendall & Kendall Systems Analysis and Design, 9e Process Specifications.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Programming Techniques Non-declarative needs (VRH 3.8) Program design in the.
© Copyright Eliyahu Brutman Programming Techniques Course.
Demystifying Architectural Styles Nikunj Mehta 3/11/02Demystifying Architectural Styles2 Architectural Styles Characterize –Structure, i.e. external.
SE-565 Software System Requirements More UML Diagrams.
C++ fundamentals.
Kendall & KendallCopyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall 9 Kendall & Kendall Systems Analysis and Design, 9e Process Specifications.
Basic Concepts The Unified Modeling Language (UML) SYSC System Analysis and Design.
© 2001 P. Van Roy and S. Haridi 1 Teaching Programming Broadly and Deeply: The Kernel Language Approach July 17, 2002 Peter Van Roy Université catholique.
9/12/2004 P. Van Roy, BCS talk 1 Concepts, Techniques, and Models of Computer Programming Dec. 9, 2004 Peter Van Roy Université catholique de Louvain Louvain-la-Neuve,
Chapter 10 Architectural Design
11 1 Object oriented DB (not in book) Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Learning objectives: What.
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
© 2002 P. Van Roy and S. Haridi 1 Teaching Programming with the Kernel Language Approach October 7, 2002 Functional and Declarative Programming in Education.
Feb. 24, 2005 P. Van Roy, SIGCSE 2005, BoF session 1 A Concepts-Based Approach for Teaching Programming SIGCSE 2005 Birds of a Feather Session Feb. 24,
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Lecture 9: Chapter 9 Architectural Design
Dynamic Choreographies Safe Runtime Updates of Distributed Applications Ivan Lanese Computer Science Department University of Bologna/INRIA Italy Joint.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
Architecture styles Pipes and filters Object-oriented design Implicit invocation Layering Repositories.
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
1 Causal-Consistent Reversible Debugging Ivan Lanese Focus research group Computer Science and Engineering Department University of Bologna/INRIA Bologna,
An Ontological Framework for Web Service Processes By Claus Pahl and Ronan Barrett.
Lyra – A service-oriented and component-based method for the development of communicating systems (by Sari Leppänen, Nokia/NRC) Traditionally, the design,
Unit 2 Architectural Styles and Case Studies | Website for Students | VTU NOTES | QUESTION PAPERS | NEWS | RESULTS 1.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHSIC Hardware Description Language  Required Reading: –These Slides –VHDL Tutorial  Very High Speed.
S. Haridi and P. Van Roy1 Concurrency and State Seif Haridi KTH Peter Van Roy UCL.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
1 Software Engineering: A Practitioner’s Approach, 6/e Chapter 10a: Architectural Design Software Engineering: A Practitioner’s Approach, 6/e Chapter 10a:
S. Haridi and P. Van Roy1 Introduction to Programming Seif Haridi KTH Peter Van Roy UCL.
12 Chapter 12: Advanced Topics in Object-Oriented Design Systems Analysis and Design in a Changing World, 3 rd Edition.
Architecture View Models A model is a complete, simplified description of a system from a particular perspective or viewpoint. There is no single view.
Week 04 Object Oriented Analysis and Designing. What is a model? A model is quicker and easier to build A model can be used in simulations, to learn more.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
Concurrent Object-Oriented Programming Languages Chris Tomlinson Mark Scheevel.
CS 501: Software Engineering Fall 1999 Lecture 15 Object-Oriented Design I.
1 7 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 7 The Object-Oriented Approach to Requirements.
Migratable User Interfaces: Beyond Migratory Interfaces Donatien Grolaux Jean Vanderdonckt Peter Van Roy.
UML (Unified Modeling Language)
SysML and Modelica Integration Working Group Meeting 3/11/09 Peter Fritzson Wladimir Schamai.
Chapter 9 Architectural Design. Why Architecture? The architecture is not the operational software. Rather, it is a representation that enables a software.
Adding Concurrency to a Programming Language Peter A. Buhr and Glen Ditchfield USENIX C++ Technical Conference, Portland, Oregon, U. S. A., August 1992.
Programming as an Engineering Discipline: The Kernel Language Approach
Course Outcomes of Object Oriented Modeling Design (17630,C604)
Object-Oriented Analysis and Design
Higher-Order Programming: Iterative computation (CTM Section 3
Lecture 28 Concurrent, Responsive GUIs
Business System Development
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Specifying collaborative decision-making systems
Chapter 20 Object-Oriented Analysis and Design
Introduction to Programming Concepts (VRH )
Presentation transcript:

Extracts from the upcoming book « Concepts, Techniques, and Models of Computer Programming » June 18, 2001 Workshop on Multiparadigm Programming with OO Languages (MPOOL) European Conference on Object-Oriented Programming (ECOOP) Peter Van Roy UCL, Louvain-la-Neuve, Belgium SICS, Stockholm, Sweden Seif Haridi KTH + SICS, Stockholm, Sweden

Overview Context of the book –Computer science education –Multiple programming « paradigms » –Comprehensive treatment of programming techniques –Students should be taught concepts as well as languages Three illustrative examples –To show what can be gained by bringing concepts up front Concurrency made easy User interface design made easy Uses and limits of declarative programming Conclusions –We will be teach-testing the book next fall

Context The current trend in CS education is to restrict the student to one or two programming paradigms The most extreme case is where a single rather complex paradigm, object-oriented programming, and a single language, Java, are used as a general-purpose approach to solve all problems The purpose of the book is to be a counterweight to this trend. We want to teach programming concepts, not limited to languages, to show programming in its full richness. The book can be described as a successor to « Structure and Interpretation of Computer Programs » by Abelson & Sussman The latest draft is always available at

The book The book organizes programming in three categories: –Concepts: compositionality, encapsulation, lexical scoping, higher- orderness, capability property, concurrency, dataflow, laziness, state, inheritance,... –Techniques: how to write programs with these concepts –Computation models (« paradigms »): data entities, operations, and a language Paradigms emerge in a natural way (a kind of epiphenomenon) when programming, depending on which concepts one uses and which properties hold of the program Each paradigm has its own properties and reasoning techniques, which is why the book is organized around them It is natural for programs to use several paradigms together

The formalism The painful choice: using many languages or one language? –Previously, many languages was the only choice (Leda notwithstanding) –This has changed with the Oz work, making one language a reasonable alternative The book uses subsets of the Oz language to model the programming paradigms. There are four reasons: –Oz was designed to integrate programming concepts into a coherent whole –Oz incorporates ten years of application development experience: its concepts and techniques have been tested in real use (industrial projects, deployed applications) –Oz has a complete and simple formal semantics –Oz has a high-quality fully-featured implementation, the Mozart Programming System (see ) Oz does not have a Java-compatible syntax –We consider it an impossible task, but be our guest... –In any case, computer scientists should be familiar with several notations We do not know any other formalism that covers so much ground so well –But we could be mistaken: please let us know!

Concurrency In an object-oriented setting, concurrency is always used in an imperative style –This is complex and difficult to learn: observable nondeterminism, race conditions, monitors, task layering –Concurrent programming is important. We would like to teach it to second year students! Traditional techniques are a recipe for disaster. There are simpler forms of concurrency –Dataflow concurrency: add threads to a functional language and use dataflow to decouple independent calculations –Active objects: each object executes sequentially in its own thread, objects communicate through asynchronous channels Both avoid most of the complexities while still giving the advantages of concurrent execution We will teach one or both in a second-year course next fall

Dataflow concurrency Dataflow = block on data availability Add dataflow variables to functional language declare X0 X1 X2 X3 Y0 Y1 Y2 in Y0=1+X0 Y1=Y0+X1 Y2=Y1+X2 thread X0=1 end thread X1=1 end thread X2=1 end X0 1 X1 X2 Y0 Y1 Y2 X0=1 X1=1 X2=1 threads

Dataflow concurrency A system can be concurrent and still confluent Dataflow concurrency has this property Here is a simple example: fun {Fibo N} if N=<2 then 1 else F1 F2 in thread {Fibo N-1 F1} end {Fibo N-2 F2} F1+F2 end

Dataflow concurrency Producer-consumer with dataflow fun {Prod N Max} if N<Max then N|{Prod N+1 Max} else nil end end fun {Cons Xs A} case Xs of X|Xr then {Cons Xr A+X} [] nil then A end end local Xs S in thread Xs={Prod } end thread S={Cons Xs 0} end end Prod and Cons threads share list Xs Dataflow behavior of case statement (synchronizing on data availability) gives stream communication No other concurrency control needed Xs ProdCons

Dataflow concurrency Lazy producer-consumer with dataflow fun lazy {Prod N} N|{Prod N+1} end fun {Cons Xs A Max} if Max>0 then case Xs of X|Xr then {Cons Xr A+X Max-1} end else A end end local Xs S in thread Xs={Prod 0} end thread S={Cons Xs } end end Lazy = demand-driven Flow control: the consumer decides how many list elements to create Dataflow behavior ensures concurrent stream communication (note « lazy » annotation)

Active objects An active object is a concurrent entity to which any other active object can send messages The active object reads the messages in arrival order and sequentially executes an action for each message An active object’s behavior is defined by a class, just like a passive object Active objects can be considered either as primitive or as defined with a thread, a passive object, and a communication channel Creation: A={NewActive Class Init}

Event manager with active objects An event manager contains a set of event handlers Each handler is a triple Id#F#S where Id identifies it, F is the state update function, and S is the state Reception of an event causes all triples to be replaced by Id#F#{F E S} (transition from F to {F E S}) The manager EM is an active object with four methods: –{EM init} initializes the event manager –{EM event(E)} posts event E at the manager –{EM add(F S Id)} adds new handler with F, S, and returns Id –{EM delete(Id S)} removes handler Id, returns state This example taken from real use in Erlang

Defining the event manager Mix of functional and object-oriented style class EventManager attr handlers meth init handlers<-nil end meth event(E) handlers<- fun {$ Id#F#S} Id#F#{F E S} end} end meth add(F S Id) Id={NewName} end meth delete(Did DS) fun {$ Id#F#S} DId==Id end [_#_#DS]} end State transition done using functional programming

Using the event manager Simple memory-based handler keeps list of events EM={NewActive EventManager init} MemH=fun {$ E Buf} E|Buf end Id={EM add(MemH nil $)} {EM event(a1)} {EM event(a2)}... An event handler is purely functional, yet when put in the event manager, the latter is a concurrent imperative program. This is an example of impedance matching between paradigms.

Defining active objects Define NewActive in terms of existing New (passive object creation) by adding one port and one thread fun {NewActive Class Init} S P Obj in {NewPort S P} Obj={New Class Init} thread for M in S do {Obj M} end end proc {$ M} {Send P M} end end For loop does dataflow synchronization (like case statement) Sending to a port causes message to appear on stream Port is created together with a stream (dataflow list)

Concurrency - conclusions Dataflow concurrency is the simplest: it has no observable nondeterminism (limited expressiveness) Dataflow concurrency permits stream communication Active objects extend stream communication with many- to-one communication, which makes them as expressive as the passive object / monitor approach Active objects can be used together with passive objects, where the active object is used as a serializer Both dataflow concurrency and active objects require cheap threads to be practical

User interface design Three approaches: –Imperative approach (AWT, Swing, tcl/tk, …): maximum expressiveness but also maximum development cost –Interface builders: adequate for the part of the UI known before the application runs –Declarative approach: reduced development cost but limited expressiveness All are unsatisfactory for dynamic user interfaces

Mixed declarative/imperative approach to UI design Using both approaches together is advantageous: –Declarative specification is a data structure. It is concise and can be manipulated with all the power of the language. –Imperative specification is a program. It has maximum expressiveness. This makes creating dynamic user interfaces particularly easy This is important for model-based UI design, an important design methodology in the Human-Computer Interface research community

Mixed approach Declarative part –A widget is a record. A full UI specification is a nested record. –The nested record specifies interface structure and resize behavior, and all widget types with their initial states Imperative part –External events cause action procedures to be executed (sequentially, in the window’s thread) –Widgets have handler objects, which allows the application to control them

Example user interface W=td(lr(label(text:«Enter your name») entry(handle:E)) button(text:«Ok» action:P))... {Build W}... {E set(text:«Type here»)}... Result={E get(text:$)} Nested record with handler object E and action procedure P Call handler Construct interface (window & handler)

Widgets Widget = rectangular area with particular behavior Examples (as records): –label(text:«Hello») –text(handle:H tdscrollbar:true) –button(text:«Ok» action:P) –lr(W1 W2... Wn) –td(W1 W2... Wn) –placeholder(handle:H) {H set(W)} Compositional Dynamic

Declarative resize behavior Resizing is dynamic but specified declaratively –This is a case where the limited expressiveness of the declarative description is good enough Declarative specification with « glue » Consider widget W inside another: W = (... glue: ) – nswe : stretch horizontal and vertical – we : stretch horizontal, centered vertical – w : left justified, centered vertical – (none): centered, keeps natural size W n s we

Example dynamic interface W=placeholder(handle:P)... {P set(label(text:«Hello»))}... {P set(entry(text:«World»))} Any UI specification can be put in the placeholder at run-time

Calculating interfaces (1) Calculate interface directly from internal data representation Data=[«Name»#«Roger» «Surname»#«Rabbit»] Result= {ListToRecord td {Map Data fun {$ L#E} lr(label(text:L) entry(init:E)) end}} Result=td(lr(label(text:«Name») entry(init:«Roger»)) lr(label(text:«Surname») entry(init:«Rabbit»)))

Calculating interfaces (2) Calculate several interfaces from the same data Choose between representations according to run-time condition Data Editable interface Placeholder widget View-only interface With language support (syntax and implementation) for record operations and functional programming this is very concise

Uses and limits of declarative programming When is a declarative paradigm appropriate and when is state and/or concurrency needed? –An important question that arouses strong religious feelings Naive limits of declarative programming: –Need for many small modifications of large structures (e.g., simulations) –Need for components that evolve independently (e.g., interactive behavior) –Need for components that have to learn from past behavior These limits can be overcome within the declarative paradigm: –State threading (e.g., monads) allows incremental modifications and learning –Dataflow concurrency allows independent components and learning, but not observable nondeterminism –Feeding external nondeterminism allows observable nondeterminism A final limit remains: –The components of a declarative program are tied together, if the program needs state threading or has observable nondeterminism. That is, the components are overspecified: their interfaces contain information that should be hidden. –In these cases, the declarative program is not fully decomposable

Conclusions Combining programming paradigms is a natural and powerful way to program –It corresponds most naturally to the underlying concepts –It does not impose artificial restrictions on what can be expressed Students should be taught starting from the underlying concepts –If they understand the concepts, then they can easily learn any language –They will see that many apparent difficulties are not due to the concepts, but to design decisions specific to particular languages –We have given two examples. The book has many more examples and has principled discussions on how to program with multiple paradigms. –The book covers many more paradigms than we could touch on in this short talk: functional programming (strict and lazy), logic programming (deterministic and nondeterministic), concurrency (in many forms), state (including components and objects), constraint programming, distributed programming. –We will be teach-testing the book throughout the next academic year