Date post: | 28-Nov-2014 |
Category: |
Technology |
Upload: | kimmens |
View: | 1,308 times |
Download: | 1 times |
Subjective-CBringing Context to Mobile Platform Programming
ICTEAM / UCLouvain / Belgium
Alfredo Cádiz Jean-Christophe Libbrecht
Julien Goffaux
Software Language Engineering
Sebastián GonzálezNicolás Cardozo
Kim Mens
3rd International Conference on
13 October 2010Thursday 21 October 2010
Subjective-CBringing Context to Mobile Platform Programming
ICTEAM / UCLouvain / Belgium
Alfredo Cádiz Jean-Christophe Libbrecht
Julien Goffaux
Software Language Engineering
Sebastián GonzálezNicolás Cardozo
Kim Mens
3rd International Conference on
Sebastián González
Kim Mens
13 October 2010Thursday 21 October 2010
Subjective-CBringing Context to Mobile Platform Programming
ICTEAM / UCLouvain / Belgium
Alfredo Cádiz Jean-Christophe Libbrecht
Julien Goffaux
Software Language Engineering
Sebastián GonzálezNicolás Cardozo
Kim Mens
3rd International Conference on
Sebastián González
Kim Mens
13 October 2010Thursday 21 October 2010
2
Research Context
Thursday 21 October 2010
??
??
?
?
programming in isolation programming in contextProgramming Mindset Towards a Mindset Shift
3
Research Goal
Thursday 21 October 2010
class phone {
method receive ( call ) {
if ( phone.isOffHook( ) )play( phone.callWaitingSignal( ), 2 );
else if ( phone.environment( ).acoustics( ).isQuiet( ) )phone.vibrate( 5 );
else if ( phone.user( ).isUnavailable( ) )forwardCall( call, phone.forwardNumber( ) );
elseplay( phone.ringTone( ), 10 );
}
conditional statements
4
Contemporary Solution
Thursday 21 October 2010
class phone {
method receive ( call ) {
if ( phone.isOffHook( ) )play( phone.callWaitingSignal( ), 2 );
else if ( phone.environment( ).acoustics( ).isQuiet( ) )phone.vibrate( 5 );
else if ( phone.user( ).isUnavailable( ) )forwardCall( call, phone.forwardNumber( ) );
elseplay( phone.ringTone( ), 10 );
}
conditional statements
4
Contemporary Solution
Thursday 21 October 2010
class phone {
method receive ( call ) {
if ( phone.isOffHook( ) )play( phone.callWaitingSignal( ), 2 );
else if ( phone.environment( ).acoustics( ).isQuiet( ) )phone.vibrate( 5 );
else if ( phone.user( ).isUnavailable( ) )forwardCall( call, phone.forwardNumber( ) );
elseplay( phone.ringTone( ), 10 );
}
conditional statements
4
Contemporary Solution
·
Thursday 21 October 2010
class phone {
method receive ( call ) {
if ( phone.isOffHook( ) )play( phone.callWaitingSignal( ), 2 );
else if ( phone.environment( ).acoustics( ).isQuiet( ) )phone.vibrate( 5 );
else if ( phone.user( ).isUnavailable( ) )forwardCall( call, phone.forwardNumber( ) );
elseplay( phone.ringTone( ), 10 );
}
conditional statements
4
Contemporary Solution
·
Thursday 21 October 2010
class phone {
method receive ( call ) {
if ( phone.isOffHook( ) )play( phone.callWaitingSignal( ), 2 );
else if ( phone.environment( ).acoustics( ).isQuiet( ) )phone.vibrate( 5 );
else if ( phone.user( ).isUnavailable( ) )forwardCall( call, phone.forwardNumber( ) );
elseplay( phone.ringTone( ), 10 );
}
conditional statements
4
Contemporary Solution
∅
·
Thursday 21 October 2010
class phone {
method receive ( call ) {
if ( phone.isOffHook( ) )play( phone.callWaitingSignal( ), 2 );
else if ( phone.environment( ).acoustics( ).isQuiet( ) )phone.vibrate( 5 );
else if ( phone.user( ).isUnavailable( ) )forwardCall( call, phone.forwardNumber( ) );
elseplay( phone.ringTone( ), 10 );
}
conditional statements
Tangled
Fixed 4
Scattered
Contemporary Solution
∅
·
Thursday 21 October 2010
class Phone{ attribute strategy; method receive ( call ) { strategy.receive ( call ); } }
special software architecturesContemporary Solution
5Thursday 21 October 2010
class UnavailableStrategy{ method receive ( call ) { ... } }
class QuietStrategy{ method receive ( call ) { ... } }
class OffHookStrategy{ method receive ( call ) { ... } }
class DefaultStrategy{ method receive ( call ) { ... } }
class Phone{ attribute strategy; method receive ( call ) { strategy.receive ( call ); } }
UnavailableStrategy
OffHookStrategy
special software architecturesContemporary Solution
5
QuietStrategyPhone
DefaultStrategy
·
Thursday 21 October 2010
class UnavailableStrategy{ method receive ( call ) { ... } }
class QuietStrategy{ method receive ( call ) { ... } }
class OffHookStrategy{ method receive ( call ) { ... } }
class DefaultStrategy{ method receive ( call ) { ... } }
class Phone{ attribute strategy; method receive ( call ) { strategy.receive ( call ); } }
UnavailableStrategy
OffHookStrategy
special software architecturesContemporary Solution
5
QuietStrategyPhone
DefaultStrategy
·
Thursday 21 October 2010
class UnavailableStrategy{ method receive ( call ) { ... } }
class QuietStrategy{ method receive ( call ) { ... } }
class OffHookStrategy{ method receive ( call ) { ... } }
class DefaultStrategy{ method receive ( call ) { ... } }
class Phone{ attribute strategy; method receive ( call ) { strategy.receive ( call ); } }
UnavailableStrategy
OffHookStrategy
special software architecturesContemporary Solution
5
QuietStrategyPhone
DefaultStrategy
Infrastructural burdenFixed adaptation points
Thursday 21 October 2010
Solution Language engineering approach
6
Thursday 21 October 2010
Solution Language engineering approach
Prototypes
Multiple dispatch
PMD
6SmalltalkSelfCLOS
Thursday 21 October 2010
Solution Language engineering approach
Prototypes
Multiple dispatch
PMD
Subjective Programming
6SmalltalkSelfCLOS
Thursday 21 October 2010
Context Management
Solution Language engineering approach
Prototypes
Multiple dispatch
PMD
Subjective Programming
6SmalltalkSelfCLOS
Thursday 21 October 2010
Context Management
Solution Language engineering approach
Prototypes
Multiple dispatch
Context-Oriented Programming
PMD
Subjective Programming
6SmalltalkSelfCLOS
Thursday 21 October 2010
Context Management
Solution
Ambience
Language engineering approach
Prototypes
Multiple dispatch
Context-Oriented Programming
PMD
[DLS’07]
Subjective Programming
6SmalltalkSelfCLOS
Thursday 21 October 2010
Context Management
Solution
Ambience
Language engineering approach
Prototypes
Multiple dispatch
Context-Oriented Programming
PMD
[DLS’07]
Subjective Programming
6SmalltalkSelfCLOS
Thursday 21 October 2010
Context Management
Solution
Ambience
Language engineering approach
Prototypes
Multiple dispatch
Context-Oriented Programming
Open Classes
Single dispatch
PMD
[DLS’07]
Objective-C
Subjective Programming
6SmalltalkSelf CCLOS
Thursday 21 October 2010
Context Management
Solution
Ambience
Language engineering approach
Prototypes
Multiple dispatch
Context-Oriented Programming
Open Classes
Single dispatch
Subjective Programming
PMD
[DLS’07]
Objective-C
Subjective Programming
6SmalltalkSelf CCLOS
Thursday 21 October 2010
Context ManagementContext Management
Solution
Ambience
Language engineering approach
Prototypes
Multiple dispatch
Context-Oriented Programming
Open Classes
Single dispatch
Subjective Programming
PMD
[DLS’07]
Objective-C
Subjective Programming
6SmalltalkSelf CCLOS
Thursday 21 October 2010
Context ManagementContext Management
Solution
Ambience
Language engineering approach
Prototypes
Multiple dispatch
Context-Oriented Programming
Open Classes
Single dispatch
Subjective Programming
PMD
[DLS’07]
Context-Oriented Programming
Objective-C
Subjective Programming
6SmalltalkSelf CCLOS
Thursday 21 October 2010
Context ManagementContext Management
Solution
Ambience
Language engineering approach
Prototypes
Multiple dispatch
Context-Oriented Programming
Subjective-C
Open Classes
Single dispatch
Subjective Programming
PMD
[DLS’07]
Context-Oriented Programming
Objective-C
Subjective Programming
6SmalltalkSelf CCLOS
Thursday 21 October 2010
Context ManagementContext Management
Solution
Ambience
Language engineering approach
Prototypes
Multiple dispatch
Context-Oriented Programming
Subjective-C
Open Classes
Single dispatch
Subjective Programming
PMD
[DLS’07]
Context-Oriented Programming
Objective-C
Subjective Programming
6SmalltalkSelf CCLOS
Thursday 21 October 2010
1 General mindset
2 Context definition
3 Context-specific behaviour
4 Context relations
5 Implementation
6 Efficiency
Subjective-C
7Thursday 21 October 2010
external
Context-Aware System Architecture
Subjective-C
context effectcontext
information
ActuatorsSensors
arbitratedcontext changes
World
Context Discovery
Context Management
Active Context
8
internal
Application Behaviour
1 Mindset1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Thursday 21 October 2010
Low battery charge
High CPU load
Battery charge = 220 mAh
Computationally accessible information
Idle cycles = 11 MHz
action can be taken
Well-defined situation(Contexts)
Location = 51°26′N 5°29′E Eindhoven
no semantics
What is context?
9
Z axis = 0.03 Landscape orientation
situations can be reified
2 Context1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Thursday 21 October 2010
10
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Case Study3 Behaviour
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
UILabel classdrawTextInRect:Draws the receiver’s text in the specified rectangle.- (void)drawTextInRect:(CGRect)rectParametersrect
The rectangle in which to draw the text.DiscussionYou 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.AvailabilityAvailable in iOS 2.0 and later.Declared InUILabel.h
Case Study
11
3 Behaviour
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
UILabel classdrawTextInRect:Draws the receiver’s text in the specified rectangle.- (void)drawTextInRect:(CGRect)rectParametersrect
The rectangle in which to draw the text.DiscussionYou 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.AvailabilityAvailable in iOS 2.0 and later.Declared InUILabel.h
Case Study
11
3 Behaviour
Thursday 21 October 2010
Subjective-C: Look & Feel
@implementation UILabel (color)#context Landscape- (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; [superContext drawTextInRect:rect];}@end
12
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency3 Behaviour
Thursday 21 October 2010
Subjective-C: Look & Feel
@implementation UILabel (color)#context Landscape- (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; [superContext drawTextInRect:rect];}@end
Open classesObjective-C
12
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency3 Behaviour
Thursday 21 October 2010
Subjective-C: Look & Feel
@implementation UILabel (color)#context Landscape- (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; [superContext drawTextInRect:rect];}@end
Open classesObjective-CCOP
Subjective-C
12
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency3 Behaviour
Thursday 21 October 2010
Subjective-C: Look & Feel
@implementation UILabel (color)#context Landscape- (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; [superContext drawTextInRect:rect];}@end
Open classesObjective-CCOP
Subjective-C
✓ Adaptation of any existing component✓ No access to original source code needed✓ Adaptations can be cleanly modularised
12
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency3 Behaviour
Thursday 21 October 2010
Context Relations
HDVideo BatteryHighRequirement
Museum Quiet
Eindhoven NetherlandsStrong Inclusion
Weak Inclusion
Landscape PortraitExclusion
13
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency4 Relations
Thursday 21 October 2010
// Create contextsContext* Room = [[Context alloc] initWithName:@"Room"];Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"];Context* Day = [[Context alloc] initWithName:@"Day"];Context* Night = [[Context alloc] initWithName:@"Night"];...
// Register contexts[CONTEXT addContext:Room];[CONTEXT addContext:Bedroom];[CONTEXT addContext:Day];[CONTEXT addContext:Night];...
// Establish context relations[Day addExclusionRelationWith:Night];[Bedroom addHardInclusionRelationWith:Room];...
Programmatic Context Definition
14
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency4 Relations
Thursday 21 October 2010
// Create contextsContext* Room = [[Context alloc] initWithName:@"Room"];Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"];Context* Day = [[Context alloc] initWithName:@"Day"];Context* Night = [[Context alloc] initWithName:@"Night"];...
// Register contexts[CONTEXT addContext:Room];[CONTEXT addContext:Bedroom];[CONTEXT addContext:Day];[CONTEXT addContext:Night];...
// Establish context relations[Day addExclusionRelationWith:Night];[Bedroom addHardInclusionRelationWith:Room];...
Context Declaration Language
14
Relations:
Day >< NightSun >< Rain
Livingroom -> TVLivingroom -> WindowLivingroom -> LuminosityLivingroom -> TemperatureKitchen -> LuminosityBedroom -> TemperatureBedroom -> LuminosityBedroom -> WindowBathroom -> TemperatureBathroom -> Luminosity
Bathroom => RoomKitchen => RoomLivingroom => RoomBedroom => Room
TV =< ElectricityLuminosity =< ElectricityWindow =< Sun
Contexts:
RoomLivingroomKitchenBedroomBathroomDayNight
TVWindowTemperatureLuminosity
SunRainElectricity
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency4 Relations
Thursday 21 October 2010
// Create contextsContext* Room = [[Context alloc] initWithName:@"Room"];Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"];Context* Day = [[Context alloc] initWithName:@"Day"];Context* Night = [[Context alloc] initWithName:@"Night"];...
// Register contexts[CONTEXT addContext:Room];[CONTEXT addContext:Bedroom];[CONTEXT addContext:Day];[CONTEXT addContext:Night];...
// Establish context relations[Day addExclusionRelationWith:Night];[Bedroom addHardInclusionRelationWith:Room];...
Context Declaration Language
14
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency4 Relations
Thursday 21 October 2010
// Register context-specific methods[MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom) forClass:[DomoticsServerViewController class] forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil] withDefautSel:@selector(getActiveRoom) withPriority:0];...
// Create contextsContext* Room = [[Context alloc] initWithName:@"Room"];Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"];Context* Day = [[Context alloc] initWithName:@"Day"];Context* Night = [[Context alloc] initWithName:@"Night"];...
// Register contexts[CONTEXT addContext:Room];[CONTEXT addContext:Bedroom];[CONTEXT addContext:Day];[CONTEXT addContext:Night];...
// Establish context relations[Day addExclusionRelationWith:Night];[Bedroom addHardInclusionRelationWith:Room];...
14
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency4 Relations
#context Bedroom-(Context*) getActiveRoom{! return [CONTEXT getContext:@"Bedroom"];}
Other Generated Code
Thursday 21 October 2010
// Register context-specific methods[MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom) forClass:[DomoticsServerViewController class] forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil] withDefautSel:@selector(getActiveRoom) withPriority:0];...
// Create contextsContext* Room = [[Context alloc] initWithName:@"Room"];Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"];Context* Day = [[Context alloc] initWithName:@"Day"];Context* Night = [[Context alloc] initWithName:@"Night"];...
// Register contexts[CONTEXT addContext:Room];[CONTEXT addContext:Bedroom];[CONTEXT addContext:Day];[CONTEXT addContext:Night];...
// Establish context relations[Day addExclusionRelationWith:Night];[Bedroom addHardInclusionRelationWith:Room];...
14
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency4 Relations
Other Generated Code
Thursday 21 October 2010
@implementation LowpassFilter
-(void)addAcceleration:(UIAcceleration*)accel{! double alpha = filterConstant;!! if(adaptive)! ! alpha = ... // big formula to calculate the alpha level!! x = accel.x * alpha + x * (1.0 - alpha);! y = accel.y * alpha + y * (1.0 - alpha);! z = accel.z * alpha + z * (1.0 - alpha);}
-(NSString*)name{! return adaptive ? @"Adaptive Lowpass Filter" : @"Lowpass Filter";}
...
15
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Application Contexts
Thursday 21 October 2010
16
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
@implementation LowpassFilter
#context LowPassFilter-(void)addAcceleration:(UIAcceleration*)accel{! double alpha = [self getAlpha:accel];!! x = accel.x * alpha + x * (1.0 - alpha);! y = accel.y * alpha + y * (1.0 - alpha);! z = accel.z * alpha + z * (1.0 - alpha);}
#context !Adaptive-(double) getAlpha:(UIAcceleration*)accel{! return filterConstant;}
#context LowPassFilter Adaptive-(double) getAlpha:(UIAcceleration*)accel {! return // big formula to calculate the alpha level;}
Application Contexts
Thursday 21 October 2010
16
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
@implementation LowpassFilter
#context LowPassFilter-(void)addAcceleration:(UIAcceleration*)accel{! double alpha = [self getAlpha:accel];!! x = accel.x * alpha + x * (1.0 - alpha);! y = accel.y * alpha + y * (1.0 - alpha);! z = accel.z * alpha + z * (1.0 - alpha);}
#context !Adaptive-(double) getAlpha:(UIAcceleration*)accel{! return filterConstant;}
#context LowPassFilter Adaptive-(double) getAlpha:(UIAcceleration*)accel {! return // big formula to calculate the alpha level;}
Relations:
LowPassFilter >< HighPassFilter LowPassFilter => FilterHighPassFilter => Filter
Contexts:
AdaptivePausedLowPassFilterHighPassFilterFilter
Application Contexts
Thursday 21 October 2010
Implementation
17
dynamic method pre-dispatch
UILabel@property NSString *text@property UIFont *font...- (void)Portrait_drawTextInRect:(CGRect)rect- (void)Landscape_drawTextInRect:(CGRect)rect- (void)Default_drawTextInRect:(CGRect)rect- (void)drawTextInRect:(CGRect)rect
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency5 Implementation
Default impl
Landscape impl
Portrait impl
Thursday 21 October 2010
Implementation
17
dynamic method pre-dispatch
UILabel@property NSString *text@property UIFont *font...- (void)Portrait_drawTextInRect:(CGRect)rect- (void)Landscape_drawTextInRect:(CGRect)rect- (void)Default_drawTextInRect:(CGRect)rect- (void)drawTextInRect:(CGRect)rect
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency5 Implementation
Default impl
Landscape impl
Portrait implvtable
Thursday 21 October 2010
Implementation
17
dynamic method pre-dispatch
UILabel@property NSString *text@property UIFont *font...- (void)Portrait_drawTextInRect:(CGRect)rect- (void)Landscape_drawTextInRect:(CGRect)rect- (void)Default_drawTextInRect:(CGRect)rect- (void)drawTextInRect:(CGRect)rect
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency5 Implementation
Default impl
Landscape impl
Portrait impl
Thursday 21 October 2010
Implementation
17
dynamic method pre-dispatch
UILabel@property NSString *text@property UIFont *font...- (void)Portrait_drawTextInRect:(CGRect)rect- (void)Landscape_drawTextInRect:(CGRect)rect- (void)Default_drawTextInRect:(CGRect)rect- (void)drawTextInRect:(CGRect)rect
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency5 Implementation
Default impl
Landscape impl
Portrait impl
Thursday 21 October 2010
Implementation
17
dynamic method pre-dispatch
UILabel@property NSString *text@property UIFont *font...- (void)Portrait_drawTextInRect:(CGRect)rect- (void)Landscape_drawTextInRect:(CGRect)rect- (void)Default_drawTextInRect:(CGRect)rect- (void)drawTextInRect:(CGRect)rect
[CONTEXT activateContextWithName: @"Landscape"];
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency5 Implementation
Default impl
Landscape impl
Portrait impl
Thursday 21 October 2010
Implementation
17
dynamic method pre-dispatch
UILabel@property NSString *text@property UIFont *font...- (void)Portrait_drawTextInRect:(CGRect)rect- (void)Landscape_drawTextInRect:(CGRect)rect- (void)Default_drawTextInRect:(CGRect)rect- (void)drawTextInRect:(CGRect)rect
[CONTEXT activateContextWithName: @"Landscape"];
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency5 Implementation
Default impl
Landscape impl
Portrait impl
Thursday 21 October 2010
Implementation
17
dynamic method pre-dispatch
UILabel@property NSString *text@property UIFont *font...- (void)Portrait_drawTextInRect:(CGRect)rect- (void)Landscape_drawTextInRect:(CGRect)rect- (void)Default_drawTextInRect:(CGRect)rect- (void)drawTextInRect:(CGRect)rect
[CONTEXT activateContextWithName: @"Landscape"];
[CONTEXT deactivateContextWithName: @"Landscape"];
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency5 Implementation
Default impl
Landscape impl
Portrait impl
Thursday 21 October 2010
Implementation
17
dynamic method pre-dispatch
UILabel@property NSString *text@property UIFont *font...- (void)Portrait_drawTextInRect:(CGRect)rect- (void)Landscape_drawTextInRect:(CGRect)rect- (void)Default_drawTextInRect:(CGRect)rect- (void)drawTextInRect:(CGRect)rect
[CONTEXT activateContextWithName: @"Landscape"];
[CONTEXT deactivateContextWithName: @"Landscape"];
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency5 Implementation
Default impl
Landscape impl
Portrait impl
Thursday 21 October 2010
Implementation
17
dynamic method pre-dispatch
UILabel@property NSString *text@property UIFont *font...- (void)Portrait_drawTextInRect:(CGRect)rect- (void)Landscape_drawTextInRect:(CGRect)rect- (void)Default_drawTextInRect:(CGRect)rect- (void)drawTextInRect:(CGRect)rect
‣ no additional cost for method invocations‣ cost incurred at context switching time
[CONTEXT activateContextWithName: @"Landscape"];
[CONTEXT deactivateContextWithName: @"Landscape"];
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency5 Implementation
Default impl
Landscape impl
Portrait impl
Thursday 21 October 2010
-(void) test:(int) mode {
if (mode == 1) result = 1;
...
else if (mode == N) result = N;
else result = 0;}
Objective-C
#context C1-(void) test{ result = 1; }
...
#context CN-(void) test{ result = N; }
-(void) test{ result = 0; }
Subjective-C
18
conditional statementscontext-specific methods
What is more efficient?1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency6 Efficiency
Thursday 21 October 2010
#context C1-(void) test{ result = 1; }
...
#context CK-(void) test{ result = K; }
...
#context CN-(void) test{ result = N; }
-(void) test{ result = 0; }
Subjective-Cfor (int i = 0; i < 1000; i++) {
// switch context if (i % 2) [CONTEXT activateContextWithName:@"CK"]; else [CONTEXT deactivateContextWithName:@"CK"];
// call test method repeatedly for (int j = 0; j < M; j++) [self test];}
19
Benchmark Setup1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency6 Efficiency
Thursday 21 October 2010
#context C1-(void) test{ result = 1; }
...
#context CK-(void) test{ result = K; }
...
#context CN-(void) test{ result = N; }
-(void) test{ result = 0; }
Subjective-Cfor (int i = 0; i < 1000; i++) {
// switch context if (i % 2) [CONTEXT activateContextWithName:@"CK"]; else [CONTEXT deactivateContextWithName:@"CK"];
// call test method repeatedly for (int j = 0; j < M; j++) [self test];}
19
Benchmark Setup
N: number of variationsK: selected branchM: method calls per mode switch
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency6 Efficiency
Thursday 21 October 2010
-(void) test:(int) mode {
if (mode == 1) result = 1;
...
if (mode == K) result = K;
...
else if (mode == N) result = N;
else result = 0;}
Objective-Cfor (int i = 0; i < 1000; i++) {
// toggle operation mode if (i % 2) mode = K; else mode = 0;
// call test method repeatedly for (int j = 0; j < M; j++) [self test: mode];}
20
Benchmark Setup
N: number of variationsK: selected branchM: method calls per mode switch
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency6 Efficiency
Thursday 21 October 2010
10−1
100
101
102
103
104
105
100 101 102 103 104 105
milliseconds
method calls per context switch (M)
M∗
Subjective-C
Objective-C
Fig. 6. Performance comparison using logarithmic scale (N = 50, K = 50).
From the benchmarks we can conclude that the efficiency of Subjective-C
is highly dependent on its usage. Most benefits are obtained for contexts that
are not switched too often with respect to the rate of usage of affected methods.
For many common cases this condition will hold: context switches will usually be
sparse enough in time with respect to affected method calls. In particular, in each
of the three case studies described in Section 5, the Subjective-C implementation
did not give raise to apparent performance penalties.
Note that although gained efficiency for some use cases is a desirable side
effect of using Subjective-C, the more important benefits remain in the realm
of software engineering: improved modularisation, reusability, extensibility, and
dynamic adaptability.
7 Discussion, Limitations and Future Work
Even though Subjective-C is usable for application development on mobile de-
vices as suggested in Section 5, it still has rough edges we need to iron out. This
section describes the most salient ones, starting with the more technical and
going over to the more conceptual.
Super-Context Translation A caveat of the implementation presented in
Section 4.3 is the impossibility to retrieve the return value from a superContextmessage. Our current solution consists in having a different syntax when the
return value is needed, which complements the definition of the superContextconstruct given in Section 2.4:
[superContext selector] => variable;[superContext keyword: argument ...] => variable;
-(void) test:(int) mode {
if (mode == 1)
result = 1;
else if (mode == 2)
result = 2;
...
else if (mode == N)
result = N;
else
result = 0;
}
-(void) test {
result = 0;
}
#context C1
-(void) test {
result = 1;
}
...
#context CN
-(void) test {
result = N;
}
Snippet 11. Dummy test methods in Objective-C (left) and Subjective-C (right) with
N + 1 behavioural variants. The choice of the variant depends on the application’s
current operating mode and the application’s current execution context, respectively.
for (int i = 0; i < 1000; i++) {
if (i % 2)
[CONTEXT activateContextWithName:@"CK"]; // mode = K;
else
[CONTEXT deactivateContextWithName:@"CK"]; // mode = 0;
for (int j = 0; j < M; j++)
[self test];
}
Snippet 12. Code to measure the relative cost of context changes with respect to
context-dependent method invocation in Subjective-C; the Objective-C counterpart is
analogous and is therefore just suggested as comments.
calls per context switch. Beyond this point, Subjective-C is more efficient than
Objective-C; the execution time in both approaches will tend to grow linearly,
although Objective-C will have a considerably higher slope due to conditional
statement execution,7 besides the cost of method invocation which is incurred in
both approaches. Table 4 summarises the intersection points for various values
of N and K, including the case of Fig. 6.
N K M∗
5 1 8230
10 1 4708
50 1 3405
5 5 4521
10 10 2653
50 50 1148
Table 4. Efficiency meeting point M∗between Subjective-C and Objective-C.
7This difference is not apparent in Fig. 6 because of the logarithmic scale.
21
N: number of variationsK: selected branchM: method calls per context switch
iPhone 3GS, iOS 4.0
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency6 Efficiency
Thursday 21 October 2010
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
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Thursday 21 October 2010
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
http://ambience.info.ucl.ac.be
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency
Time for questions!
Thursday 21 October 2010