Thanks to steady advances in hardware, mobile computing platforms are nowadays much more connected to their physical and logical environment than ever before. To ease the construction of adaptable applications that are smarter with respect to their execution environment, the context-oriented programming paradigm has emerged. However, up until now there has been no proof that this emerging paradigm can be implemented and used effectively on mobile devices, probably the kind of platform which is most subject to dynamically changing contexts. In this presentation we show how to effectively achieve core context-oriented abstractions on top of Objective-C, a mainstream language for mobile device programming. The result is Subjective-C, a language which goes beyond currently existing context-oriented languages by providing a rich encoding of context interdependencies. Our initial validation cases and efficiency benchmarks make us confident that context-oriented programming can become mainstream in mobile application development.
How to Troubleshoot Apps for the Modern Connected Worker
Subjective-C: Bringing Context to Mobile Platform Programming
1. 3rd International Conference on
Software Language Engineering
Subjective-C
Bringing Context to Mobile Platform Programming
ICTEAM / UCLouvain / Belgium
Sebastián González Alfredo Cádiz
Nicolás Cardozo Jean-Christophe Libbrecht
Kim Mens Julien Goffaux
13 October 2010
Thursday 21 October 2010
2. 3rd International Conference on
Software Language Engineering
Subjective-C
Bringing Context to Mobile Platform Programming
ICTEAM / UCLouvain / Belgium
Sebastián González
Sebastián González Alfredo Cádiz
Nicolás Cardozo Jean-Christophe Libbrecht
Kim Mens
Kim Mens Julien Goffaux
13 October 2010
Thursday 21 October 2010
3. 3rd International Conference on
Software Language Engineering
Subjective-C
Bringing Context to Mobile Platform Programming
ICTEAM / UCLouvain / Belgium
Sebastián González
Sebastián González Alfredo Cádiz
Nicolás Cardozo Jean-Christophe Libbrecht
Kim Mens
Kim Mens Julien Goffaux
13 October 2010
Thursday 21 October 2010
30. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Context-Aware System Architecture
World
Sensors Actuators
Subjective-C
Context Application
Discovery Behaviour
external internal context
effect
context
information arbitrated
context
Context changes Active
Management Context
8
Thursday 21 October 2010
31. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
What is context?
Computationally Well-defined situation
accessible information (Contexts)
Z axis = 0.03 Landscape orientation
Battery charge = 220 mAh Low battery charge
Idle cycles = 11 MHz High CPU load
Location = 51°26′N 5°29′E Eindhoven
no semantics action can be taken
situations can be reified
9
Thursday 21 October 2010
32. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Case Study
10
Thursday 21 October 2010
33. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Case Study
UILabel class
drawTextInRect:
Draws the receiver’s text in the specified rectangle.
- (void)drawTextInRect:(CGRect)rect
Parameters
rect
The rectangle in which to draw the text.
Discussion
You should not call this method directly. This method
should only be overridden by subclasses that want to
modify the default drawing behavior for the label’s text.
Availability
Available in iOS 2.0 and later.
Declared In
UILabel.h
11
Thursday 21 October 2010
34. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Case Study
UILabel class
drawTextInRect:
Draws the receiver’s text in the specified rectangle.
- (void)drawTextInRect:(CGRect)rect
Parameters
rect
The rectangle in which to draw the text.
Discussion
You should not call this method directly. This method
should only be overridden by subclasses that want to
modify the default drawing behavior for the label’s text.
Availability
Available in iOS 2.0 and later.
Declared In
UILabel.h
11
Thursday 21 October 2010
57. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
What is more efficient?
Subjective-C Objective-C
context-specific methods conditional statements
#context C1 -(void) test:(int) mode {
-(void) test
{ result = 1; } if (mode == 1)
result = 1;
...
...
#context CN
-(void) test else if (mode == N)
{ result = N; } result = N;
-(void) test else
{ result = 0; } result = 0;
}
18
Thursday 21 October 2010
58. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Benchmark Setup
Subjective-C
#context C1
-(void) test for (int i = 0; i < 1000; i++) {
{ result = 1; }
// switch context
... if (i % 2)
[CONTEXT activateContextWithName:@"CK"];
#context CK else
-(void) test [CONTEXT deactivateContextWithName:@"CK"];
{ result = K; }
// call test method repeatedly
... for (int j = 0; j < M; j++)
[self test];
#context CN }
-(void) test
{ result = N; }
-(void) test
{ result = 0; }
19
Thursday 21 October 2010
59. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Benchmark Setup
Subjective-C
#context C1
-(void) test for (int i = 0; i < 1000; i++) {
{ result = 1; }
// switch context
... if (i % 2)
[CONTEXT activateContextWithName:@"CK"];
#context CK else
-(void) test [CONTEXT deactivateContextWithName:@"CK"];
{ result = K; }
// call test method repeatedly
... for (int j = 0; j < M; j++)
[self test];
#context CN }
-(void) test
{ result = N; }
N: number of variations
-(void) test K: selected branch
{ result = 0; }
M: method calls per mode switch 19
Thursday 21 October 2010
60. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Benchmark Setup
Objective-C
-(void) test:(int) mode {
for (int i = 0; i < 1000; i++) {
if (mode == 1)
result = 1; // toggle operation mode
if (i % 2)
... mode = K;
else
if (mode == K) mode = 0;
result = K;
// call test method repeatedly
... for (int j = 0; j < M; j++)
[self test: mode];
else if (mode == N) }
result = N;
else
N: number of variations
result = 0; K: selected branch
}
M: method calls per mode switch 20
Thursday 21 October 2010
61. e case of 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Fig. 6.
N K M∗ N: number of variations
5 1 8230
10 1 4708 K: selected branch
50
5
1
5
3405
4521 M: method calls per context switch
10 10 2653
50 50 1148 105
ting point M ∗ between Subjective-C and Objective-C.
Subjective-C
104 Objective-C
parent in Fig. 6 because of the logarithmic scale.
103
milliseconds
M∗
102
101
100
10−1
100 101 102 103 104 105
method calls per context switch (M)
Fig. 6. Performance comparison using logarithmic scale (N = 50, K = 50).
iPhone 3GS, iOS 4.0 21
Thursday 21 October 2010
62. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Subjective-C
✓ Context-oriented programming for a C-flavoured language
✓ Runs on mobile phones
✓ Run-time behaviour adaptation of any component (incl. 3rd party)
✓ Permits clean modularisation of adaptations
✓ Maximises adaptation points while avoiding architectural burden
✓ Context interdependency system
✓ Context declaration language
✓ Can be more efficient than dynamic dispatch
➡ Thread-local adaptations
➡ Improving efficiency
➡ Usability (IDE integration)
➡ Ensure behaviour consistency
Thursday 21 October 2010
63. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Subjective-C
✓ Context-oriented programming for a C-flavoured language
✓ Runs on mobile phones
✓ Run-time behaviour adaptation of any component (incl. 3rd party)
✓ Permits clean modularisation of adaptations
✓ Maximises adaptation points while avoiding architectural burden
✓ Context interdependency system
✓ Context declaration language
✓ Can be more efficient than dynamic dispatch
➡ Thread-local adaptations
➡ Improving efficiency
➡ Usability (IDE integration)
Time for questions!
➡ Ensure behaviour consistency
http://ambience.info.ucl.ac.be
Thursday 21 October 2010