SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
©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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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)
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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