Behavioral Programming A review of recent research:
description
Transcript of Behavioral Programming A review of recent research:
![Page 1: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/1.jpg)
1
Behavioral ProgrammingA review of recent research:
ECOOP’10, ASE’10, ICFP’10, ICPC’11, EMSOFT’11, AGERE’11, ICTAI’11
David Harel, Assaf Marron, Smadar Szekely, Gera Weiss
Ben-Gurion Universityof the Negev
Weizmann Institute of Science
![Page 2: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/2.jpg)
2
The Behavioral Programming Vision
Can complex software be developed from simple threads of behavior
by automatic interweaving ?
![Page 3: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/3.jpg)
3
A 6-day trip from NY to LA
Daily Schedule
… can software be developed this way?
...Drive for 4 hrs.
Stop for Lunch
Drive for 5 hrs. …
Driving Directions
…
…
Humans interweave behavior threads all the time…
![Page 4: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/4.jpg)
LSC & BPJ: From requirements to code
4
LSC: A visual language for scenario specification Damm and Harel 2001, Harel and Marelly 2003
Natural yet executable scenario-based specification
Initially for requirement specification, evolved into a programming language
PlayGo – an IDE for programming with LSC
class AddHotFiveTimes extends BThread { public void runBThread() { for (int i=1; i<=5; i++) { bSync(addHot, none, none); } } }
BPJ: A package for programming scenarios in Java (and equivalents for other languages)
Harel, Marron, and Weiss 2010
Bringing advantages of scenario-based specification to programming
Integrate with & complement other paradigms (OOP, aspects, rule-based, agile, …).
![Page 5: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/5.jpg)
5
class AddHotFiveTimes extends BThread {
public void runBThread() { for (int i=1; i<=5; i++) { bSync(addHot, none, none); } } }
Req. 3.1
Patch 7.1
class Interleave extends BThread { public void runBThread() { while (true) { bSync(none, addHot, addCold); bSync(none, addCold, addHot); } } }
Req. 5.2.9class AddColdFiveTimes BThread { public void runBThread() { for (int i=1; i<=5; i++) { bSync(addCold, none, none);
} } }
Incremental development in Java with BPJ
Behavior Threads
![Page 6: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/6.jpg)
6
Need to accommodate a cross-cutting requirement? Add a module
Need to refine an inter-object scenario? Add a module
Need to remove a behavior? Add a module
. . . ? Add a module
Why do we need this?
A key benefit: incremental development
No need to modify existing code
![Page 7: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/7.jpg)
7
Behavior execution cycle
1. All behavior threads (b-threads) post declarations:
• Request events: propose events to be considered for triggering;
• Wait for events: ask to be notified when events are triggered;
• Block events: temporarily forbid the triggering of events.
2. When all declarations are collected:
An event that is requested and not blocked is selected.
All b-threads waiting for this event can update their declaration
![Page 8: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/8.jpg)
8
Behavior execution cycle
B-s
Block
Wait
Request
Behavior Threads
![Page 9: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/9.jpg)
9
Behavior execution cycle
B-s
Block
Wait
Request
Behavior Threads
![Page 10: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/10.jpg)
10
Behavior execution cycle
B-s
Block
Wait
Request
Behavior Threads
![Page 11: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/11.jpg)
11
addHotaddHotaddHotaddHotaddHot
Example: Coding b-threads in Javaclass AddHotFiveTimes extends BThread { public void runBThread() { for (int i=1; i<=5; i++) { bSync(addHot, none, none); } } }
class AddColdFiveTimes BThread { public void runBThread() { for (int i=1; i<=5; i++) { bSync(addCold, none, none); } } }
class Interleave extends BThread { public void runBThread() { while (true) { bSync(none, addHot, addCold); bSync(none, addCold, addHot); } } }
addHotaddHotaddHotaddHotaddHot addCold addCold addCold addCold addCold
addHot addColdaddHot addColdaddHot addColdaddHot addColdaddHot addCold
![Page 12: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/12.jpg)
12
Main application: reactive systems
Complexity stems from the need to interleave many simultaneous behaviors
![Page 13: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/13.jpg)
Alignment of code modules with requirements
13
bSync(none, X<1,2> , none);
bSync(none, X<2,2> , none);
bSync(O<3,1> , none, none);
When I put two Xs in a line, you need to put an O in the third square
![Page 14: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/14.jpg)
14
Each new game rule or strategy is added in a
separate b-thread
without changing existing code
![Page 15: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/15.jpg)
15
Some answers to common questions and challenges
What about conflicting requirements? Model Checking Incremental development …
Scalability in terms number of behaviors and interleaving complexity?
Agent oriented architectures Machine learning for event selection …
Comprehension of systems constructed by behavior composition?
Trace visualization tool …
![Page 16: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/16.jpg)
16
request SpeedUpR2
block SlowDownR2
request SlowDownR4
block SpeedUpR4
To correct the angle:
request SpeedUpR2
block SlowDownR2
request SpeedUpR1
request SpeedUpR4
block SlowDownR4
block SlowDownR3request SpeedUpR3
block SlowDownR1To increase altitude:
Example: Flying a quadrotor helicopter
Selected event:
SpeedUpR2
![Page 17: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/17.jpg)
Balancing a quadrotor – behaviorally
17
![Page 18: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/18.jpg)
18
Challenges and future research
Scalability • Tools for developing many b-threads• Architectures for efficient execution of many b-threads
Dealing with conflicts and under-specification • Model checking• Automatic program repair• Machine learning
Evaluation• Empirical studies• Complex applications• Theoretical advantages
and limitations
And much more…
![Page 19: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/19.jpg)
Incremental development in Java, LSC, and other languages
19
Summary:The behavioral programming paradigm
Create complex software by interweaving simple b-threads
Application agnostic mechanism for b-thread interweaving
?
![Page 20: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/20.jpg)
20
BACKUP SLIDES
![Page 21: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/21.jpg)
21
Model-checking behavioral programs “in-vivo” (c.f. Java Path Finder)
Backtrack using Apache javaflow continuations
Transition using standard execution (by the native JVM)
State matching and search pruning by b-threads
State tagging for safety and liveness properties by b-threads
Notations for nondeterministic transitions
![Page 22: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/22.jpg)
22
Behavior Thread States b-thread states at bSync ..labelNextVerificationState( “A” ); bSync( … ); if( lastEvent == event1 ) {
. .
.labelNextVerificationState( “B” );
bSync( … );}
if( lastEvent == event2 ) {...labelNextVerificationState( “C” );
bSync( … );}
A
B
C
event1
event2
![Page 23: Behavioral Programming A review of recent research:](https://reader035.fdocuments.us/reader035/viewer/2022062501/5681676c550346895ddc546a/html5/thumbnails/23.jpg)
23
Program states are the Cartesian product of b-thread states
Behavioral Program State Graph
A
B
C
D
E
G
I
HADG
BDG
…
…AEG
……
BDHAEI