SlideShare una empresa de Scribd logo
1 de 63
Descargar para leer sin conexión
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
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
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
Research Context




                                              2
Thursday 21 October 2010
Research Goal
     Programming Mindset                   Towards a Mindset Shift
      programming in isolation              programming in context

                               ?
           ?
                                       ?



       ?
                                   ?
                           ?

                                                                     3
Thursday 21 October 2010
Contemporary Solution
                                          conditional statements
                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( ) );
                           else
                             play( phone.ringTone( ), 10 );
                }




                                                                                      4
Thursday 21 October 2010
Contemporary Solution
                                          conditional statements
                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( ) );
                           else
                             play( phone.ringTone( ), 10 );
                }




                                                                                      4
Thursday 21 October 2010
Contemporary Solution
                                          conditional statements
                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( ) );
                           else
                             play( phone.ringTone( ), 10 );
                }




                                                                                          4
Thursday 21 October 2010
Contemporary Solution
                                          conditional statements
                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( ) );
                           else
                             play( phone.ringTone( ), 10 );
                }




                                                                                          4
Thursday 21 October 2010
Contemporary Solution
                                          conditional statements
                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( ) );
                           else
                             play( phone.ringTone( ), 10 );                           ∅
                }




                                                                                              4
Thursday 21 October 2010
Contemporary Solution
                                          conditional statements
                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( ) );
                           else
                             play( phone.ringTone( ), 10 );                           ∅
                }

                                                            Tangled
                                                            Scattered
                                                            Fixed                             4
Thursday 21 October 2010
Contemporary Solution
                                  special software architectures




                     class Phone
                     { attribute strategy;
                       method receive ( call )
                       { strategy.receive ( call ); } }




                                                                   5
Thursday 21 October 2010
Contemporary Solution
                                  special software architectures

                                                          class DefaultStrategy
                                                          { method receive ( call ) { ... } }

                                                          class QuietStrategy
                     class Phone                          { method receive ( call ) { ... } }   ·
                     { attribute strategy;
                       method receive ( call )            class OffHookStrategy
                       { strategy.receive ( call ); } }   { method receive ( call ) { ... } }

                                                          class UnavailableStrategy
                                                          { method receive ( call ) { ... } }




                                                                                                    5
Thursday 21 October 2010
Contemporary Solution
                                  special software architectures

                                                          class DefaultStrategy
                                                          { method receive ( call ) { ... } }

                                                          class QuietStrategy
                     class Phone                          { method receive ( call ) { ... } }   ·
                     { attribute strategy;
                       method receive ( call )            class OffHookStrategy
                       { strategy.receive ( call ); } }   { method receive ( call ) { ... } }

                                                          class UnavailableStrategy
                                                          { method receive ( call ) { ... } }




                                                                                                    5
Thursday 21 October 2010
Contemporary Solution
                                  special software architectures

                                                          class DefaultStrategy
                                                          { method receive ( call ) { ... } }

                                                          class QuietStrategy
                     class Phone                          { method receive ( call ) { ... } }
                     { attribute strategy;
                       method receive ( call )            class OffHookStrategy
                       { strategy.receive ( call ); } }   { method receive ( call ) { ... } }

                                                          class UnavailableStrategy
                                                          { method receive ( call ) { ... } }


                                                Infrastructural burden
                                                Fixed adaptation points
                                                                                                5
Thursday 21 October 2010
Solution           Language engineering approach




                                                           6
Thursday 21 October 2010
Solution                          Language engineering approach




                     Multiple dispatch
                           Prototypes

                             PMD
                                   CLOS
                                          Self   Smalltalk                6
Thursday 21 October 2010
Solution                          Language engineering approach




              Subjective Programming
                     Multiple dispatch
                           Prototypes

                             PMD
                                   CLOS
                                          Self   Smalltalk                6
Thursday 21 October 2010
Solution                          Language engineering approach




                    Context Management
              Subjective Programming
                     Multiple dispatch
                           Prototypes

                             PMD
                                   CLOS
                                          Self   Smalltalk                6
Thursday 21 October 2010
Solution                          Language engineering approach




     Context-Oriented Programming
                    Context Management
              Subjective Programming
                     Multiple dispatch
                           Prototypes

                             PMD
                                   CLOS
                                          Self   Smalltalk                6
Thursday 21 October 2010
Solution                           Language engineering approach



                     Ambience             [DLS’07]


     Context-Oriented Programming
                    Context Management
              Subjective Programming
                     Multiple dispatch
                           Prototypes

                             PMD
                                   CLOS
                                            Self     Smalltalk             6
Thursday 21 October 2010
Solution                           Language engineering approach



                     Ambience             [DLS’07]


     Context-Oriented Programming
                    Context Management
              Subjective Programming
                     Multiple dispatch
                           Prototypes

                             PMD
                                   CLOS
                                            Self     Smalltalk             6
Thursday 21 October 2010
Solution                           Language engineering approach



                     Ambience             [DLS’07]


     Context-Oriented Programming
                    Context Management
              Subjective Programming
                     Multiple dispatch                           Single dispatch
                           Prototypes                            Open Classes

                             PMD                                 Objective-C
                                   CLOS                          C
                                            Self     Smalltalk                     6
Thursday 21 October 2010
Solution                           Language engineering approach



                     Ambience             [DLS’07]


     Context-Oriented Programming
                    Context Management
              Subjective Programming                        Subjective Programming
                     Multiple dispatch                           Single dispatch
                           Prototypes                            Open Classes

                             PMD                                 Objective-C
                                   CLOS                          C
                                            Self     Smalltalk                       6
Thursday 21 October 2010
Solution                           Language engineering approach



                     Ambience             [DLS’07]


     Context-Oriented Programming
                    Context Management                       Context Management
              Subjective Programming                        Subjective Programming
                     Multiple dispatch                           Single dispatch
                           Prototypes                            Open Classes

                             PMD                                 Objective-C
                                   CLOS                          C
                                            Self     Smalltalk                       6
Thursday 21 October 2010
Solution                           Language engineering approach



                     Ambience             [DLS’07]

                                                        Context-Oriented Programming
     Context-Oriented Programming
                    Context Management                       Context Management
              Subjective Programming                        Subjective Programming
                     Multiple dispatch                           Single dispatch
                           Prototypes                            Open Classes

                             PMD                                 Objective-C
                                   CLOS                          C
                                            Self     Smalltalk                         6
Thursday 21 October 2010
Solution                           Language engineering approach



                     Ambience             [DLS’07]          Subjective-C
                                                        Context-Oriented Programming
     Context-Oriented Programming
                    Context Management                       Context Management
              Subjective Programming                        Subjective Programming
                     Multiple dispatch                           Single dispatch
                           Prototypes                            Open Classes

                             PMD                                 Objective-C
                                   CLOS                          C
                                            Self     Smalltalk                         6
Thursday 21 October 2010
Solution                           Language engineering approach



                     Ambience             [DLS’07]          Subjective-C
                                                        Context-Oriented Programming
     Context-Oriented Programming
                    Context Management                       Context Management
              Subjective Programming                        Subjective Programming
                     Multiple dispatch                           Single dispatch
                           Prototypes                            Open Classes

                             PMD                                 Objective-C
                                   CLOS                          C
                                            Self     Smalltalk                         6
Thursday 21 October 2010
Subjective-C
                           1 General mindset
                           2 Context definition
                           3 Context-specific behaviour
                           4 Context relations
                           5 Implementation
                           6 Efficiency
                                                         7
Thursday 21 October 2010
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
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
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency



                                 Case Study




                                                                                        10
Thursday 21 October 2010
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
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
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency



                      Subjective-C: Look & Feel

                           @implementation UILabel (color)
                           #context Landscape
                           - (void)drawTextInRect:(CGRect)rect {
                             self.textColor = [UIColor greenColor];
                             [superContext drawTextInRect:rect];
                           }
                           @end




                                                                                        12
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency



                      Subjective-C: Look & Feel
                                                                       Open classes
                           @implementation UILabel (color)     Objective-C
                           #context Landscape
                           - (void)drawTextInRect:(CGRect)rect {
                             self.textColor = [UIColor greenColor];
                             [superContext drawTextInRect:rect];
                           }
                           @end




                                                                                        12
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency



                      Subjective-C: Look & Feel
                                                                       Open classes
                           @implementation UILabel (color)     Objective-C
     COP                   #context Landscape
  Subjective-C
                           - (void)drawTextInRect:(CGRect)rect {
                             self.textColor = [UIColor greenColor];
                             [superContext drawTextInRect:rect];
                           }
                           @end




                                                                                        12
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency



                      Subjective-C: Look & Feel
                                                                       Open classes
                            @implementation UILabel (color)     Objective-C
     COP                    #context Landscape
  Subjective-C
                            - (void)drawTextInRect:(CGRect)rect {
                              self.textColor = [UIColor greenColor];
                              [superContext drawTextInRect:rect];
                            }
                            @end

                  ✓        Adaptation of any existing component
                  ✓        No access to original source code needed
                  ✓        Adaptations can be cleanly modularised
                                                                                        12
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency



                               Context Relations
       Strong Inclusion                Eindhoven                    Netherlands


         Weak Inclusion                 Museum                          Quiet

                Requirement             HDVideo                     BatteryHigh


                           Exclusion   Landscape                       Portrait

                                                                                        13
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


   Programmatic Context Definition
    // Create contexts
    Context*        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
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


          Context Declaration Language
                                               Contexts:      Relations:
    // Create contexts
    Context* Room = [[Context alloc] initWithName:@"Room"];
    Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"]; >< Night
                                              Room            Day
    Context*                                  Livingroom
             Day = [[Context alloc] initWithName:@"Day"];     Sun >< Rain
    Context*                                  Kitchen
             Night = [[Context alloc] initWithName:@"Night"];
    ...                                       Bedroom         Livingroom -> TV
                                              Bathroom        Livingroom -> Window
    // Register contexts                      Day             Livingroom -> Luminosity
    [CONTEXT addContext:Room];
    [CONTEXT addContext:Bedroom];             Night           Livingroom -> Temperature
    [CONTEXT addContext:Day];                                 Kitchen -> Luminosity
    [CONTEXT addContext:Night];               TV              Bedroom -> Temperature
    ...                                       Window          Bedroom -> Luminosity
                                              Temperature     Bedroom -> Window
    // Establish context relations            Luminosity      Bathroom -> Temperature
    [Day addExclusionRelationWith:Night];
    [Bedroom addHardInclusionRelationWith:Room];              Bathroom -> Luminosity
    ...                                       Sun
                                              Rain            Bathroom => Room
                                              Electricity     Kitchen => Room
                                                              Livingroom => Room
                                                              Bedroom => Room

                                                              TV =< Electricity
                                                              Luminosity =< Electricity
                                                              Window =< Sun               14
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


          Context Declaration Language
    // Create contexts
    Context*        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
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                           Other Generated Code
    // Create contexts
    Context*        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                  #context Bedroom
    [Day addExclusionRelationWith:Night];    -(Context*) getActiveRoom{
    [Bedroom addHardInclusionRelationWith:Room];
                                             ! return [CONTEXT getContext:@"Bedroom"];
    ...
                                                    }

    // Register context-specific methods
    [MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom)
             forClass:[DomoticsServerViewController class]
             forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil]
             withDefautSel:@selector(getActiveRoom)
             withPriority:0];
    ...
                                                                                         14
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                           Other Generated Code
    // Create contexts
    Context*        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];
    ...


    // Register context-specific methods
    [MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom)
             forClass:[DomoticsServerViewController class]
             forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil]
             withDefautSel:@selector(getActiveRoom)
             withPriority:0];
    ...
                                                                                        14
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency



                           Application Contexts
         @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
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency



                           Application Contexts
         @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;
         }
                                                16
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency



                           Application Contexts
         @implementation LowpassFilter
                                                            Contexts:

         #context LowPassFilter
                                                     Adaptive
         -(void)addAcceleration:(UIAcceleration*)accel
                                                     Paused
         {
                                                     LowPassFilter
         ! double alpha = [self getAlpha:accel];
                                                     HighPassFilter
         !
         ! x = accel.x * alpha + x * (1.0 - alpha); Filter
         ! y = accel.y * alpha + y * (1.0 - alpha); Relations:
         ! z = accel.z * alpha + z * (1.0 - alpha);
         }
                                                            LowPassFilter >< HighPassFilter
                                                            LowPassFilter => Filter
         #context !Adaptive
                                                            HighPassFilter => Filter
         -(double) getAlpha:(UIAcceleration*)accel{
         ! return filterConstant;
         }

         #context LowPassFilter Adaptive
         -(double) getAlpha:(UIAcceleration*)accel {
         ! return // big formula to calculate the alpha level;
         }
                                                16
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                             Implementation
                           dynamic method pre-dispatch

        UILabel
        @property NSString *text
        @property UIFont *font
        ...
                                                                        Portrait impl
        - (void)Portrait_drawTextInRect:(CGRect)rect
        - (void)Landscape_drawTextInRect:(CGRect)rect                  Landscape impl
        - (void)Default_drawTextInRect:(CGRect)rect
        - (void)drawTextInRect:(CGRect)rect                              Default impl




                                                                                        17
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                             Implementation
                           dynamic method pre-dispatch

        UILabel
        @property NSString *text
        @property UIFont *font
        ...                                           vtable
                                                                        Portrait impl
        - (void)Portrait_drawTextInRect:(CGRect)rect
        - (void)Landscape_drawTextInRect:(CGRect)rect                  Landscape impl
        - (void)Default_drawTextInRect:(CGRect)rect
        - (void)drawTextInRect:(CGRect)rect                              Default impl




                                                                                        17
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                             Implementation
                           dynamic method pre-dispatch

        UILabel
        @property NSString *text
        @property UIFont *font
        ...
                                                                        Portrait impl
        - (void)Portrait_drawTextInRect:(CGRect)rect
        - (void)Landscape_drawTextInRect:(CGRect)rect                  Landscape impl
        - (void)Default_drawTextInRect:(CGRect)rect
        - (void)drawTextInRect:(CGRect)rect                              Default impl




                                                                                        17
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                             Implementation
                           dynamic method pre-dispatch

        UILabel
        @property NSString *text
        @property UIFont *font
        ...
                                                                        Portrait impl
        - (void)Portrait_drawTextInRect:(CGRect)rect
        - (void)Landscape_drawTextInRect:(CGRect)rect                  Landscape impl
        - (void)Default_drawTextInRect:(CGRect)rect
        - (void)drawTextInRect:(CGRect)rect                              Default impl




                                                                                        17
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                             Implementation
                           dynamic method pre-dispatch

        UILabel
        @property NSString *text
        @property UIFont *font
        ...
                                                                        Portrait impl
        - (void)Portrait_drawTextInRect:(CGRect)rect
        - (void)Landscape_drawTextInRect:(CGRect)rect                  Landscape impl
        - (void)Default_drawTextInRect:(CGRect)rect
        - (void)drawTextInRect:(CGRect)rect                              Default impl


        [CONTEXT activateContextWithName: @"Landscape"];




                                                                                        17
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                             Implementation
                           dynamic method pre-dispatch

        UILabel
        @property NSString *text
        @property UIFont *font
        ...
                                                                        Portrait impl
        - (void)Portrait_drawTextInRect:(CGRect)rect
        - (void)Landscape_drawTextInRect:(CGRect)rect                  Landscape impl
        - (void)Default_drawTextInRect:(CGRect)rect
        - (void)drawTextInRect:(CGRect)rect                              Default impl


        [CONTEXT activateContextWithName: @"Landscape"];




                                                                                        17
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                             Implementation
                           dynamic method pre-dispatch

        UILabel
        @property NSString *text
        @property UIFont *font
        ...
                                                                        Portrait impl
        - (void)Portrait_drawTextInRect:(CGRect)rect
        - (void)Landscape_drawTextInRect:(CGRect)rect                  Landscape impl
        - (void)Default_drawTextInRect:(CGRect)rect
        - (void)drawTextInRect:(CGRect)rect                              Default impl


        [CONTEXT activateContextWithName: @"Landscape"];
        [CONTEXT deactivateContextWithName: @"Landscape"];




                                                                                        17
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                             Implementation
                           dynamic method pre-dispatch

        UILabel
        @property NSString *text
        @property UIFont *font
        ...
                                                                        Portrait impl
        - (void)Portrait_drawTextInRect:(CGRect)rect
        - (void)Landscape_drawTextInRect:(CGRect)rect                  Landscape impl
        - (void)Default_drawTextInRect:(CGRect)rect
        - (void)drawTextInRect:(CGRect)rect                              Default impl


        [CONTEXT activateContextWithName: @"Landscape"];
        [CONTEXT deactivateContextWithName: @"Landscape"];




                                                                                        17
Thursday 21 October 2010
1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency


                             Implementation
                           dynamic method pre-dispatch

        UILabel
        @property NSString *text
        @property UIFont *font
        ...
                                                                        Portrait impl
        - (void)Portrait_drawTextInRect:(CGRect)rect
        - (void)Landscape_drawTextInRect:(CGRect)rect                  Landscape impl
        - (void)Default_drawTextInRect:(CGRect)rect
        - (void)drawTextInRect:(CGRect)rect                              Default impl


        [CONTEXT activateContextWithName: @"Landscape"];
        [CONTEXT deactivateContextWithName: @"Landscape"];

        ‣ no additional cost for method invocations
        ‣ cost incurred at context switching time                                       17
Thursday 21 October 2010
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
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
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
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
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
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
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

Más contenido relacionado

Más de kim.mens

Software Patterns
Software PatternsSoftware Patterns
Software Patternskim.mens
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoringkim.mens
 
Domain Modelling
Domain ModellingDomain Modelling
Domain Modellingkim.mens
 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworkskim.mens
 
Towards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation FrameworkTowards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation Frameworkkim.mens
 
Towards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty ApproachesTowards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty Approacheskim.mens
 
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software EngineeringBreaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineeringkim.mens
 
Context-oriented programming
Context-oriented programmingContext-oriented programming
Context-oriented programmingkim.mens
 
Basics of reflection
Basics of reflectionBasics of reflection
Basics of reflectionkim.mens
 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Javakim.mens
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in javakim.mens
 
Reflection in Ruby
Reflection in RubyReflection in Ruby
Reflection in Rubykim.mens
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Rubykim.mens
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalkkim.mens
 
A gentle introduction to reflection
A gentle introduction to reflectionA gentle introduction to reflection
A gentle introduction to reflectionkim.mens
 
Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...kim.mens
 
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)kim.mens
 
Usage contracts in a nutshell
Usage contracts in a nutshellUsage contracts in a nutshell
Usage contracts in a nutshellkim.mens
 
INGI2252 Software Measures & Maintenance
INGI2252 Software Measures & MaintenanceINGI2252 Software Measures & Maintenance
INGI2252 Software Measures & Maintenancekim.mens
 
Building an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developersBuilding an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developerskim.mens
 

Más de kim.mens (20)

Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Domain Modelling
Domain ModellingDomain Modelling
Domain Modelling
 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworks
 
Towards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation FrameworkTowards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation Framework
 
Towards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty ApproachesTowards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty Approaches
 
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software EngineeringBreaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineering
 
Context-oriented programming
Context-oriented programmingContext-oriented programming
Context-oriented programming
 
Basics of reflection
Basics of reflectionBasics of reflection
Basics of reflection
 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Java
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in java
 
Reflection in Ruby
Reflection in RubyReflection in Ruby
Reflection in Ruby
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalk
 
A gentle introduction to reflection
A gentle introduction to reflectionA gentle introduction to reflection
A gentle introduction to reflection
 
Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...
 
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
 
Usage contracts in a nutshell
Usage contracts in a nutshellUsage contracts in a nutshell
Usage contracts in a nutshell
 
INGI2252 Software Measures & Maintenance
INGI2252 Software Measures & MaintenanceINGI2252 Software Measures & Maintenance
INGI2252 Software Measures & Maintenance
 
Building an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developersBuilding an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developers
 

Último

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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Último (20)

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)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

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
  • 4. Research Context 2 Thursday 21 October 2010
  • 5. Research Goal Programming Mindset Towards a Mindset Shift programming in isolation programming in context ? ? ? ? ? ? 3 Thursday 21 October 2010
  • 6. Contemporary Solution conditional statements 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( ) ); else play( phone.ringTone( ), 10 ); } 4 Thursday 21 October 2010
  • 7. Contemporary Solution conditional statements 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( ) ); else play( phone.ringTone( ), 10 ); } 4 Thursday 21 October 2010
  • 8. Contemporary Solution conditional statements 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( ) ); else play( phone.ringTone( ), 10 ); } 4 Thursday 21 October 2010
  • 9. Contemporary Solution conditional statements 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( ) ); else play( phone.ringTone( ), 10 ); } 4 Thursday 21 October 2010
  • 10. Contemporary Solution conditional statements 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( ) ); else play( phone.ringTone( ), 10 ); ∅ } 4 Thursday 21 October 2010
  • 11. Contemporary Solution conditional statements 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( ) ); else play( phone.ringTone( ), 10 ); ∅ } Tangled Scattered Fixed 4 Thursday 21 October 2010
  • 12. Contemporary Solution special software architectures class Phone { attribute strategy; method receive ( call ) { strategy.receive ( call ); } } 5 Thursday 21 October 2010
  • 13. Contemporary Solution special software architectures class DefaultStrategy { method receive ( call ) { ... } } class QuietStrategy class Phone { method receive ( call ) { ... } } · { attribute strategy; method receive ( call ) class OffHookStrategy { strategy.receive ( call ); } } { method receive ( call ) { ... } } class UnavailableStrategy { method receive ( call ) { ... } } 5 Thursday 21 October 2010
  • 14. Contemporary Solution special software architectures class DefaultStrategy { method receive ( call ) { ... } } class QuietStrategy class Phone { method receive ( call ) { ... } } · { attribute strategy; method receive ( call ) class OffHookStrategy { strategy.receive ( call ); } } { method receive ( call ) { ... } } class UnavailableStrategy { method receive ( call ) { ... } } 5 Thursday 21 October 2010
  • 15. Contemporary Solution special software architectures class DefaultStrategy { method receive ( call ) { ... } } class QuietStrategy class Phone { method receive ( call ) { ... } } { attribute strategy; method receive ( call ) class OffHookStrategy { strategy.receive ( call ); } } { method receive ( call ) { ... } } class UnavailableStrategy { method receive ( call ) { ... } } Infrastructural burden Fixed adaptation points 5 Thursday 21 October 2010
  • 16. Solution Language engineering approach 6 Thursday 21 October 2010
  • 17. Solution Language engineering approach Multiple dispatch Prototypes PMD CLOS Self Smalltalk 6 Thursday 21 October 2010
  • 18. Solution Language engineering approach Subjective Programming Multiple dispatch Prototypes PMD CLOS Self Smalltalk 6 Thursday 21 October 2010
  • 19. Solution Language engineering approach Context Management Subjective Programming Multiple dispatch Prototypes PMD CLOS Self Smalltalk 6 Thursday 21 October 2010
  • 20. Solution Language engineering approach Context-Oriented Programming Context Management Subjective Programming Multiple dispatch Prototypes PMD CLOS Self Smalltalk 6 Thursday 21 October 2010
  • 21. Solution Language engineering approach Ambience [DLS’07] Context-Oriented Programming Context Management Subjective Programming Multiple dispatch Prototypes PMD CLOS Self Smalltalk 6 Thursday 21 October 2010
  • 22. Solution Language engineering approach Ambience [DLS’07] Context-Oriented Programming Context Management Subjective Programming Multiple dispatch Prototypes PMD CLOS Self Smalltalk 6 Thursday 21 October 2010
  • 23. Solution Language engineering approach Ambience [DLS’07] Context-Oriented Programming Context Management Subjective Programming Multiple dispatch Single dispatch Prototypes Open Classes PMD Objective-C CLOS C Self Smalltalk 6 Thursday 21 October 2010
  • 24. Solution Language engineering approach Ambience [DLS’07] Context-Oriented Programming Context Management Subjective Programming Subjective Programming Multiple dispatch Single dispatch Prototypes Open Classes PMD Objective-C CLOS C Self Smalltalk 6 Thursday 21 October 2010
  • 25. Solution Language engineering approach Ambience [DLS’07] Context-Oriented Programming Context Management Context Management Subjective Programming Subjective Programming Multiple dispatch Single dispatch Prototypes Open Classes PMD Objective-C CLOS C Self Smalltalk 6 Thursday 21 October 2010
  • 26. Solution Language engineering approach Ambience [DLS’07] Context-Oriented Programming Context-Oriented Programming Context Management Context Management Subjective Programming Subjective Programming Multiple dispatch Single dispatch Prototypes Open Classes PMD Objective-C CLOS C Self Smalltalk 6 Thursday 21 October 2010
  • 27. Solution Language engineering approach Ambience [DLS’07] Subjective-C Context-Oriented Programming Context-Oriented Programming Context Management Context Management Subjective Programming Subjective Programming Multiple dispatch Single dispatch Prototypes Open Classes PMD Objective-C CLOS C Self Smalltalk 6 Thursday 21 October 2010
  • 28. Solution Language engineering approach Ambience [DLS’07] Subjective-C Context-Oriented Programming Context-Oriented Programming Context Management Context Management Subjective Programming Subjective Programming Multiple dispatch Single dispatch Prototypes Open Classes PMD Objective-C CLOS C Self Smalltalk 6 Thursday 21 October 2010
  • 29. Subjective-C 1 General mindset 2 Context definition 3 Context-specific behaviour 4 Context relations 5 Implementation 6 Efficiency 7 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
  • 35. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Subjective-C: Look & Feel @implementation UILabel (color) #context Landscape - (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; [superContext drawTextInRect:rect]; } @end 12 Thursday 21 October 2010
  • 36. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Subjective-C: Look & Feel Open classes @implementation UILabel (color) Objective-C #context Landscape - (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; [superContext drawTextInRect:rect]; } @end 12 Thursday 21 October 2010
  • 37. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Subjective-C: Look & Feel Open classes @implementation UILabel (color) Objective-C COP #context Landscape Subjective-C - (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; [superContext drawTextInRect:rect]; } @end 12 Thursday 21 October 2010
  • 38. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Subjective-C: Look & Feel Open classes @implementation UILabel (color) Objective-C COP #context Landscape Subjective-C - (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; [superContext drawTextInRect:rect]; } @end ✓ Adaptation of any existing component ✓ No access to original source code needed ✓ Adaptations can be cleanly modularised 12 Thursday 21 October 2010
  • 39. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Context Relations Strong Inclusion Eindhoven Netherlands Weak Inclusion Museum Quiet Requirement HDVideo BatteryHigh Exclusion Landscape Portrait 13 Thursday 21 October 2010
  • 40. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Programmatic Context Definition // Create contexts Context* 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 Thursday 21 October 2010
  • 41. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Context Declaration Language Contexts: Relations: // Create contexts Context* Room = [[Context alloc] initWithName:@"Room"]; Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"]; >< Night Room Day Context* Livingroom Day = [[Context alloc] initWithName:@"Day"]; Sun >< Rain Context* Kitchen Night = [[Context alloc] initWithName:@"Night"]; ... Bedroom Livingroom -> TV Bathroom Livingroom -> Window // Register contexts Day Livingroom -> Luminosity [CONTEXT addContext:Room]; [CONTEXT addContext:Bedroom]; Night Livingroom -> Temperature [CONTEXT addContext:Day]; Kitchen -> Luminosity [CONTEXT addContext:Night]; TV Bedroom -> Temperature ... Window Bedroom -> Luminosity Temperature Bedroom -> Window // Establish context relations Luminosity Bathroom -> Temperature [Day addExclusionRelationWith:Night]; [Bedroom addHardInclusionRelationWith:Room]; Bathroom -> Luminosity ... Sun Rain Bathroom => Room Electricity Kitchen => Room Livingroom => Room Bedroom => Room TV =< Electricity Luminosity =< Electricity Window =< Sun 14 Thursday 21 October 2010
  • 42. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Context Declaration Language // Create contexts Context* 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 Thursday 21 October 2010
  • 43. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Other Generated Code // Create contexts Context* 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 #context Bedroom [Day addExclusionRelationWith:Night]; -(Context*) getActiveRoom{ [Bedroom addHardInclusionRelationWith:Room]; ! return [CONTEXT getContext:@"Bedroom"]; ... } // Register context-specific methods [MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom) forClass:[DomoticsServerViewController class] forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil] withDefautSel:@selector(getActiveRoom) withPriority:0]; ... 14 Thursday 21 October 2010
  • 44. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Other Generated Code // Create contexts Context* 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]; ... // Register context-specific methods [MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom) forClass:[DomoticsServerViewController class] forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil] withDefautSel:@selector(getActiveRoom) withPriority:0]; ... 14 Thursday 21 October 2010
  • 45. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Application Contexts @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 Thursday 21 October 2010
  • 46. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Application Contexts @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; } 16 Thursday 21 October 2010
  • 47. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Application Contexts @implementation LowpassFilter Contexts: #context LowPassFilter Adaptive -(void)addAcceleration:(UIAcceleration*)accel Paused { LowPassFilter ! double alpha = [self getAlpha:accel]; HighPassFilter ! ! x = accel.x * alpha + x * (1.0 - alpha); Filter ! y = accel.y * alpha + y * (1.0 - alpha); Relations: ! z = accel.z * alpha + z * (1.0 - alpha); } LowPassFilter >< HighPassFilter LowPassFilter => Filter #context !Adaptive HighPassFilter => Filter -(double) getAlpha:(UIAcceleration*)accel{ ! return filterConstant; } #context LowPassFilter Adaptive -(double) getAlpha:(UIAcceleration*)accel { ! return // big formula to calculate the alpha level; } 16 Thursday 21 October 2010
  • 48. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Implementation dynamic method pre-dispatch UILabel @property NSString *text @property UIFont *font ... Portrait impl - (void)Portrait_drawTextInRect:(CGRect)rect - (void)Landscape_drawTextInRect:(CGRect)rect Landscape impl - (void)Default_drawTextInRect:(CGRect)rect - (void)drawTextInRect:(CGRect)rect Default impl 17 Thursday 21 October 2010
  • 49. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Implementation dynamic method pre-dispatch UILabel @property NSString *text @property UIFont *font ... vtable Portrait impl - (void)Portrait_drawTextInRect:(CGRect)rect - (void)Landscape_drawTextInRect:(CGRect)rect Landscape impl - (void)Default_drawTextInRect:(CGRect)rect - (void)drawTextInRect:(CGRect)rect Default impl 17 Thursday 21 October 2010
  • 50. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Implementation dynamic method pre-dispatch UILabel @property NSString *text @property UIFont *font ... Portrait impl - (void)Portrait_drawTextInRect:(CGRect)rect - (void)Landscape_drawTextInRect:(CGRect)rect Landscape impl - (void)Default_drawTextInRect:(CGRect)rect - (void)drawTextInRect:(CGRect)rect Default impl 17 Thursday 21 October 2010
  • 51. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Implementation dynamic method pre-dispatch UILabel @property NSString *text @property UIFont *font ... Portrait impl - (void)Portrait_drawTextInRect:(CGRect)rect - (void)Landscape_drawTextInRect:(CGRect)rect Landscape impl - (void)Default_drawTextInRect:(CGRect)rect - (void)drawTextInRect:(CGRect)rect Default impl 17 Thursday 21 October 2010
  • 52. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Implementation dynamic method pre-dispatch UILabel @property NSString *text @property UIFont *font ... Portrait impl - (void)Portrait_drawTextInRect:(CGRect)rect - (void)Landscape_drawTextInRect:(CGRect)rect Landscape impl - (void)Default_drawTextInRect:(CGRect)rect - (void)drawTextInRect:(CGRect)rect Default impl [CONTEXT activateContextWithName: @"Landscape"]; 17 Thursday 21 October 2010
  • 53. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Implementation dynamic method pre-dispatch UILabel @property NSString *text @property UIFont *font ... Portrait impl - (void)Portrait_drawTextInRect:(CGRect)rect - (void)Landscape_drawTextInRect:(CGRect)rect Landscape impl - (void)Default_drawTextInRect:(CGRect)rect - (void)drawTextInRect:(CGRect)rect Default impl [CONTEXT activateContextWithName: @"Landscape"]; 17 Thursday 21 October 2010
  • 54. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Implementation dynamic method pre-dispatch UILabel @property NSString *text @property UIFont *font ... Portrait impl - (void)Portrait_drawTextInRect:(CGRect)rect - (void)Landscape_drawTextInRect:(CGRect)rect Landscape impl - (void)Default_drawTextInRect:(CGRect)rect - (void)drawTextInRect:(CGRect)rect Default impl [CONTEXT activateContextWithName: @"Landscape"]; [CONTEXT deactivateContextWithName: @"Landscape"]; 17 Thursday 21 October 2010
  • 55. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Implementation dynamic method pre-dispatch UILabel @property NSString *text @property UIFont *font ... Portrait impl - (void)Portrait_drawTextInRect:(CGRect)rect - (void)Landscape_drawTextInRect:(CGRect)rect Landscape impl - (void)Default_drawTextInRect:(CGRect)rect - (void)drawTextInRect:(CGRect)rect Default impl [CONTEXT activateContextWithName: @"Landscape"]; [CONTEXT deactivateContextWithName: @"Landscape"]; 17 Thursday 21 October 2010
  • 56. 1 Mindset 2 Context 3 Behaviour 4 Relations 5 Implementation 6 Efficiency Implementation dynamic method pre-dispatch UILabel @property NSString *text @property UIFont *font ... Portrait impl - (void)Portrait_drawTextInRect:(CGRect)rect - (void)Landscape_drawTextInRect:(CGRect)rect Landscape impl - (void)Default_drawTextInRect:(CGRect)rect - (void)drawTextInRect:(CGRect)rect Default impl [CONTEXT activateContextWithName: @"Landscape"]; [CONTEXT deactivateContextWithName: @"Landscape"]; ‣ no additional cost for method invocations ‣ cost incurred at context switching time 17 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