SlideShare a Scribd company logo
1 of 21
Download to read offline
©2007Martinv.Löwis
Context-Oriented Programming:
Beyond Layers
Martin v. Löwis
Marcus Denker
Oscar Nierstrasz
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Agenda
• Context-dependent Behavior
• Method Layers (PyContext example)
• Implicit Layer Activation
• Case Studies
• Context Variables
• Implementation Notes
2
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Context Dependencies
• Programs need to be aware of the context in which they
operate
– what is the state of the environment
– what user is accessing the system
– what mode is the program to be executed in
• Example: current user
– different roles may cause completely different code to be executed
(e.g. administrator may be offered different facilities)
• can be modeled through method layers
– different users acting in the same role access different data
• modeling through method layers is not adequate
• Example: dependency of program output on output device
– In OO system, rendering algorithm spreads over methods of
different classes
3
©2007Martinv.Löwis
Layers
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Method Layers
• addition of a few concepts to object-oriented programming
• layer: group of classes and methods to be used together in
dynamic scope of execution
• layered class: collection of partial definitions of a class, for
different layers
– layered methods: definitions of methods for specific layers
– layered slots: definition of instance attributes for specific layers
• (explicit) layer activation: specification of code block that
runs in the context of a layer
– inside the block, each sent message selects the method defined for
that layer
– nested activation: need to consider multiple layers in sequence
5
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Example: User-Agent Header
• Web browsers sent User-Agent header to indicate client
software (e.g. MSIE, Firefox, Safari, etc.)
– "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
• Web servers sometimes have different behavior depending
on User-Agent header
• Problem: automated web client might need to claim to
operate as a specific user agent
6
Client
HTTP Library
HTTP ServerHTTP
Request
User-Agent
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Example: User-Agent Header (2)
• Assumption: client consists of multiple modules, each using
different software layers to access underlying HTTP libraries
– explicitly specifying User-Agent to the library is not possible
• Assumption: client is multi-threaded; different threads may
need to operate in different contexts
– setting User-Agent as a global variable is not possible
• HTTP libraries in Python:
– httplib: direct access to protocol
– urllib: unifying library for http, ftp, ...
7
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
PyContext: Using Method Layers
• with statement: automatic enter/leave semantics
from useragent import HTTPUserAgent
with HTTPUserAgent("WebCOP"):
print "Using useragent layer"
get1()
get2()
• Importing useragent module automatically defines the layer
and the layered methods
• Disabling layers
from layers import Disabled
with Disabled(Layer):
code
8
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Defining Layers
• Inherit from class Layer
– Class can have arbitrary methods, instance variables, etc
class HTTPUserAgent(layers.Layer):
def __init__(self, agent):
self.agent = agent
9
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Defining Layered Methods
• Inherit a class (with arbitrary name) from both the layer and
the class to augment
• Define methods with the same name as the original methods
– Each method has automatic second parameter "context" (after self,
before explicit method parameters)
• Decorate each method with either before, after, or instead
• Context: Object indicating the layer activation
– .layer: reference to the layer object
– .result: result of the original method (for after-methods)
– .proceed: callable object denoting the continuation to the original
method (or the next layer)
10
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
class HTTPConnection(HTTPUserAgent, httplib.HTTPConnection):
# Always add a User-Agent header
@before
def endheaders(self, context):
with layers.Disabled(HTTPUserAgent):
self.putheader("User-Agent", context.layer.agent)
# suppress other User-Agent headers added
@instead
def putheader(self, context, header, value):
if header.lower() == 'user-agent':
return
return context.proceed(header, value)
11
©2007Martinv.Löwis
Implicit Activation
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Implicit Activation
• Problem: explicit activation still needs to identify point in
code where context might change or where context will be
relevant
• Objective: allow addition of layers which get activated
"automatically"
– specifically, when a condition on the environment changes
• Design issues:
– how can the system tell whether a condition becomes true?
• each layer implements an active method
– when should the active method be evaluated?
• each time a layered method is executed whose meaning depends on
whether the layer is active or not
13
©2007Martinv.Löwis
Case Studies
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Objective
• We tried to evaluate what aspects of context are common in
application programs today
• Issue: how can we find code that depends on context?
– Starting point: assume caller and callee are designed to run within
the same context
– Starting point: look for traditional examples of context
• Selected case studies: large Python applications/libraries
– Django: web application framework
– Roundup: bug tracker
– SCons: automated build tool
15
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Results
• Web applications (Django, Roundup) need to support
concept of "current" request, including authenticated user,
session data, target URL, etc.
• SCons keeps track of context in "environment": information
about the current build goal
• These things were often referred to as "context", or showed
up as pass-through parameters in methods
– Searching for "context" revealed further context-dependent code
fragments
– Searching for pass-through parameters not easily possible with pure
text searching; subject for further study
• Context information often not used to select different pieces
of code, but merely as lookup keys in associative arrays
16
©2007Martinv.Löwis
Dynamic Variables
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Motivation
• case study results lead to identification of additional concept
for context-oriented programming: Dynamic Variables
• in order to avoid pass-through parameters, a variable holding
context should be set in a caller, and then read in a nested
callee
– similar to dynamic variables in functional languages
– requires careful usage, to avoid old problems with dynamic variables
(unintentional access due to naming collisions)
• require explicit read and write operations
18
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Dynamic Variables in PyContext
• Example: current HTTP session
1. Declare dynamic variable
_session = Variable()
2. Obtain current variable (e.g. through helper function)
def current_session():
return _session.get()
3. Setup variable from dynamically-read context
def process_request(request):
session = lookup_session(request)
with _session.set(session):
dispatch_request(request)
19
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Implementation Notes
• Method layers:
– Dynamically replace methods with wrappers
• Dynamic variables:
1. perform stack walk: O(stack-depth)
2. use thread-local storage: O(1)
20
Context-oriented Programming: Beyond Layers
©2007Martinv.Löwis
Summary
• current applications (in particular webapps) show high
degree of context-awareness
• context-dependency is not made explicit in the code
• layers are a first step to making context explicit
• rehabilitation of dynamic variables necessary to support
common cases of context
21

More Related Content

What's hot

Architectural Patterns - Interactive and Event Handling Patterns
Architectural Patterns  - Interactive and Event Handling PatternsArchitectural Patterns  - Interactive and Event Handling Patterns
Architectural Patterns - Interactive and Event Handling Patternsassinha
 
Vert.x Event Driven Non Blocking Reactive Toolkit
Vert.x Event Driven Non Blocking Reactive ToolkitVert.x Event Driven Non Blocking Reactive Toolkit
Vert.x Event Driven Non Blocking Reactive ToolkitBrian S. Paskin
 
ITFT_Inter process communication
ITFT_Inter process communicationITFT_Inter process communication
ITFT_Inter process communicationSneh Prabha
 
Active Object Design Pattern
Active Object Design PatternActive Object Design Pattern
Active Object Design Patternjeremiahdjordan
 
Multi-Process JavaScript Architectures
Multi-Process JavaScript ArchitecturesMulti-Process JavaScript Architectures
Multi-Process JavaScript ArchitecturesMark Trostler
 
Reactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project ReactorReactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project ReactorKnoldus Inc.
 
Advanced Application Architecture Symfony Live Berlin 2018
Advanced Application Architecture Symfony Live Berlin 2018Advanced Application Architecture Symfony Live Berlin 2018
Advanced Application Architecture Symfony Live Berlin 2018Matthias Noback
 
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...Srikanth Reddy Pallerla
 
Build Libraries That People Love To use
Build Libraries That People Love To useBuild Libraries That People Love To use
Build Libraries That People Love To useDennis Doomen
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingsaykopatt
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx javaCongTrung Vnit
 
Vulnerability Chaining; it’s all connected
Vulnerability Chaining; it’s all connectedVulnerability Chaining; it’s all connected
Vulnerability Chaining; it’s all connectedToby Kohlenberg
 
Reactive programming and RxJS
Reactive programming and RxJSReactive programming and RxJS
Reactive programming and RxJSRavi Mone
 
ProMan(Project Management in python language using KIVY platform)
ProMan(Project Management in python language using KIVY platform)ProMan(Project Management in python language using KIVY platform)
ProMan(Project Management in python language using KIVY platform)manojsonkar
 

What's hot (20)

Architectural Patterns - Interactive and Event Handling Patterns
Architectural Patterns  - Interactive and Event Handling PatternsArchitectural Patterns  - Interactive and Event Handling Patterns
Architectural Patterns - Interactive and Event Handling Patterns
 
Project Reactor By Example
Project Reactor By ExampleProject Reactor By Example
Project Reactor By Example
 
Vert.x Event Driven Non Blocking Reactive Toolkit
Vert.x Event Driven Non Blocking Reactive ToolkitVert.x Event Driven Non Blocking Reactive Toolkit
Vert.x Event Driven Non Blocking Reactive Toolkit
 
ITFT_Inter process communication
ITFT_Inter process communicationITFT_Inter process communication
ITFT_Inter process communication
 
Active Object Design Pattern
Active Object Design PatternActive Object Design Pattern
Active Object Design Pattern
 
Multi-Process JavaScript Architectures
Multi-Process JavaScript ArchitecturesMulti-Process JavaScript Architectures
Multi-Process JavaScript Architectures
 
Reactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project ReactorReactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project Reactor
 
Advanced Application Architecture Symfony Live Berlin 2018
Advanced Application Architecture Symfony Live Berlin 2018Advanced Application Architecture Symfony Live Berlin 2018
Advanced Application Architecture Symfony Live Berlin 2018
 
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Introduction to reactive programming
Introduction to reactive programmingIntroduction to reactive programming
Introduction to reactive programming
 
Build Libraries That People Love To use
Build Libraries That People Love To useBuild Libraries That People Love To use
Build Libraries That People Love To use
 
Reflectivity Demo
Reflectivity DemoReflectivity Demo
Reflectivity Demo
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
Vulnerability Chaining; it’s all connected
Vulnerability Chaining; it’s all connectedVulnerability Chaining; it’s all connected
Vulnerability Chaining; it’s all connected
 
Reactive programming and RxJS
Reactive programming and RxJSReactive programming and RxJS
Reactive programming and RxJS
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 
ProMan(Project Management in python language using KIVY platform)
ProMan(Project Management in python language using KIVY platform)ProMan(Project Management in python language using KIVY platform)
ProMan(Project Management in python language using KIVY platform)
 

Viewers also liked

Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)Ralf Laemmel
 
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJSeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJTed Leung
 
Aspect oriented architecture
Aspect oriented architecture Aspect oriented architecture
Aspect oriented architecture tigneb
 
Produce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented ProgrammingProduce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented ProgrammingPostSharp Technologies
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented ProgrammingRodger Oates
 
Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented ProgrammingAndrey Bratukhin
 
Architecture Description Languages
Architecture Description LanguagesArchitecture Description Languages
Architecture Description LanguagesHenry Muccini
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented ProgrammingRajesh Ganesan
 
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)Yan Cui
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingYan Cui
 
Software Architecture: Architecture Description Languages
Software Architecture: Architecture Description LanguagesSoftware Architecture: Architecture Description Languages
Software Architecture: Architecture Description LanguagesHenry Muccini
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented ProgrammingAnumod Kumar
 

Viewers also liked (12)

Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
 
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJSeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
 
Aspect oriented architecture
Aspect oriented architecture Aspect oriented architecture
Aspect oriented architecture
 
Produce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented ProgrammingProduce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented Programming
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented Programming
 
Architecture Description Languages
Architecture Description LanguagesArchitecture Description Languages
Architecture Description Languages
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 
Software Architecture: Architecture Description Languages
Software Architecture: Architecture Description LanguagesSoftware Architecture: Architecture Description Languages
Software Architecture: Architecture Description Languages
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 

Similar to Context-Oriented Programming: Beyond Layers

Mantis Code Deployment Process
Mantis Code Deployment ProcessMantis Code Deployment Process
Mantis Code Deployment ProcessJen Wei Lee
 
Open shift and docker - october,2014
Open shift and docker - october,2014Open shift and docker - october,2014
Open shift and docker - october,2014Hojoong Kim
 
Orchestrating Cloud Applications With TOSCA
Orchestrating Cloud Applications With TOSCAOrchestrating Cloud Applications With TOSCA
Orchestrating Cloud Applications With TOSCAArthur Berezin
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopMax Kleiner
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - TalkMatthias Noback
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor FrameworkDamien Magoni
 
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster Cloudera, Inc.
 
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster Cloudera, Inc.
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS BackendLaurent Cerveau
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsitricks
 
They why behind php frameworks
They why behind php frameworksThey why behind php frameworks
They why behind php frameworksKirk Madera
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJSLilia Sfaxi
 
Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...
Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...
Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...Dennis Doomen
 
Decomposing the Monolith using Microservices that don't give you pain
Decomposing the Monolith using Microservices that don't give you painDecomposing the Monolith using Microservices that don't give you pain
Decomposing the Monolith using Microservices that don't give you painDennis Doomen
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsitricks
 

Similar to Context-Oriented Programming: Beyond Layers (20)

Mantis Code Deployment Process
Mantis Code Deployment ProcessMantis Code Deployment Process
Mantis Code Deployment Process
 
Open shift and docker - october,2014
Open shift and docker - october,2014Open shift and docker - october,2014
Open shift and docker - october,2014
 
WebDev Crash Course
WebDev Crash CourseWebDev Crash Course
WebDev Crash Course
 
Orchestrating Cloud Applications With TOSCA
Orchestrating Cloud Applications With TOSCAOrchestrating Cloud Applications With TOSCA
Orchestrating Cloud Applications With TOSCA
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_Workshop
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor Framework
 
Web Technology Fundamentals
Web Technology FundamentalsWeb Technology Fundamentals
Web Technology Fundamentals
 
Mini-Training: NancyFX
Mini-Training: NancyFXMini-Training: NancyFX
Mini-Training: NancyFX
 
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
 
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS Backend
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
They why behind php frameworks
They why behind php frameworksThey why behind php frameworks
They why behind php frameworks
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJS
 
Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...
Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...
Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...
 
Decomposing the Monolith using Microservices that don't give you pain
Decomposing the Monolith using Microservices that don't give you painDecomposing the Monolith using Microservices that don't give you pain
Decomposing the Monolith using Microservices that don't give you pain
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
OVS-LinuxCon 2013.pdf
OVS-LinuxCon 2013.pdfOVS-LinuxCon 2013.pdf
OVS-LinuxCon 2013.pdf
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 

More from ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsESUG
 

More from ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Recently uploaded

Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Context-Oriented Programming: Beyond Layers

  • 2. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Agenda • Context-dependent Behavior • Method Layers (PyContext example) • Implicit Layer Activation • Case Studies • Context Variables • Implementation Notes 2
  • 3. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Context Dependencies • Programs need to be aware of the context in which they operate – what is the state of the environment – what user is accessing the system – what mode is the program to be executed in • Example: current user – different roles may cause completely different code to be executed (e.g. administrator may be offered different facilities) • can be modeled through method layers – different users acting in the same role access different data • modeling through method layers is not adequate • Example: dependency of program output on output device – In OO system, rendering algorithm spreads over methods of different classes 3
  • 5. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Method Layers • addition of a few concepts to object-oriented programming • layer: group of classes and methods to be used together in dynamic scope of execution • layered class: collection of partial definitions of a class, for different layers – layered methods: definitions of methods for specific layers – layered slots: definition of instance attributes for specific layers • (explicit) layer activation: specification of code block that runs in the context of a layer – inside the block, each sent message selects the method defined for that layer – nested activation: need to consider multiple layers in sequence 5
  • 6. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Example: User-Agent Header • Web browsers sent User-Agent header to indicate client software (e.g. MSIE, Firefox, Safari, etc.) – "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" • Web servers sometimes have different behavior depending on User-Agent header • Problem: automated web client might need to claim to operate as a specific user agent 6 Client HTTP Library HTTP ServerHTTP Request User-Agent
  • 7. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Example: User-Agent Header (2) • Assumption: client consists of multiple modules, each using different software layers to access underlying HTTP libraries – explicitly specifying User-Agent to the library is not possible • Assumption: client is multi-threaded; different threads may need to operate in different contexts – setting User-Agent as a global variable is not possible • HTTP libraries in Python: – httplib: direct access to protocol – urllib: unifying library for http, ftp, ... 7
  • 8. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis PyContext: Using Method Layers • with statement: automatic enter/leave semantics from useragent import HTTPUserAgent with HTTPUserAgent("WebCOP"): print "Using useragent layer" get1() get2() • Importing useragent module automatically defines the layer and the layered methods • Disabling layers from layers import Disabled with Disabled(Layer): code 8
  • 9. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Defining Layers • Inherit from class Layer – Class can have arbitrary methods, instance variables, etc class HTTPUserAgent(layers.Layer): def __init__(self, agent): self.agent = agent 9
  • 10. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Defining Layered Methods • Inherit a class (with arbitrary name) from both the layer and the class to augment • Define methods with the same name as the original methods – Each method has automatic second parameter "context" (after self, before explicit method parameters) • Decorate each method with either before, after, or instead • Context: Object indicating the layer activation – .layer: reference to the layer object – .result: result of the original method (for after-methods) – .proceed: callable object denoting the continuation to the original method (or the next layer) 10
  • 11. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis class HTTPConnection(HTTPUserAgent, httplib.HTTPConnection): # Always add a User-Agent header @before def endheaders(self, context): with layers.Disabled(HTTPUserAgent): self.putheader("User-Agent", context.layer.agent) # suppress other User-Agent headers added @instead def putheader(self, context, header, value): if header.lower() == 'user-agent': return return context.proceed(header, value) 11
  • 13. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Implicit Activation • Problem: explicit activation still needs to identify point in code where context might change or where context will be relevant • Objective: allow addition of layers which get activated "automatically" – specifically, when a condition on the environment changes • Design issues: – how can the system tell whether a condition becomes true? • each layer implements an active method – when should the active method be evaluated? • each time a layered method is executed whose meaning depends on whether the layer is active or not 13
  • 15. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Objective • We tried to evaluate what aspects of context are common in application programs today • Issue: how can we find code that depends on context? – Starting point: assume caller and callee are designed to run within the same context – Starting point: look for traditional examples of context • Selected case studies: large Python applications/libraries – Django: web application framework – Roundup: bug tracker – SCons: automated build tool 15
  • 16. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Results • Web applications (Django, Roundup) need to support concept of "current" request, including authenticated user, session data, target URL, etc. • SCons keeps track of context in "environment": information about the current build goal • These things were often referred to as "context", or showed up as pass-through parameters in methods – Searching for "context" revealed further context-dependent code fragments – Searching for pass-through parameters not easily possible with pure text searching; subject for further study • Context information often not used to select different pieces of code, but merely as lookup keys in associative arrays 16
  • 18. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Motivation • case study results lead to identification of additional concept for context-oriented programming: Dynamic Variables • in order to avoid pass-through parameters, a variable holding context should be set in a caller, and then read in a nested callee – similar to dynamic variables in functional languages – requires careful usage, to avoid old problems with dynamic variables (unintentional access due to naming collisions) • require explicit read and write operations 18
  • 19. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Dynamic Variables in PyContext • Example: current HTTP session 1. Declare dynamic variable _session = Variable() 2. Obtain current variable (e.g. through helper function) def current_session(): return _session.get() 3. Setup variable from dynamically-read context def process_request(request): session = lookup_session(request) with _session.set(session): dispatch_request(request) 19
  • 20. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Implementation Notes • Method layers: – Dynamically replace methods with wrappers • Dynamic variables: 1. perform stack walk: O(stack-depth) 2. use thread-local storage: O(1) 20
  • 21. Context-oriented Programming: Beyond Layers ©2007Martinv.Löwis Summary • current applications (in particular webapps) show high degree of context-awareness • context-dependency is not made explicit in the code • layers are a first step to making context explicit • rehabilitation of dynamic variables necessary to support common cases of context 21