SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
Photo (cc) Horia Varlan




Virtual Separation of Concerns
Toward preprocessors 2.0




Christian Kästner
Christian Kästner: Virtual Separation of Concerns   2



          Software Product Lines & Features

 • Set of related software systems (variants)
   in a domain
 • Generated from common code base
 • Variants distinguished in terms of features
Christian Kästner: Virtual Separation of Concerns                                       3



                  Conditional Compilation with
                         Preprocessors
 ● Annotated code                                   static int _rep_queue_filedone(...
                                                        DB_ENV *dbenv;
   fragments                                            REP *rep;
                                                        __rep_fileinfo_args *rfp; {
 ● Variants with and                                #ifndef HAVE_QUEUE
                                                        COMPQUIET(rep, NULL);
   without features                                     COMPQUIET(rfp, NULL);
                                                        return (__db_no_queue_am(dbenv
                                                    #else
                                                        db_pgno_t first, last;
 ● Common for product-                                  u_int32_t flags;
                                                        int empty, ret, t_ret;
   line implementation                              #ifdef DIAGNOSTIC
                                                        DB_MSGBUF mb;
   in industry                                      #endif
                                                        ...
                                                    Excerpt from Oracle’s Berkeley DB

 Preprocessors in C, C++, Java ME, Pascal, Erlang, C#, Visual Basic, …
 GPP, GNU M4, SPLET, Frames/XVCL, Gears, pure::variants
Christian Kästner: Virtual Separation of Concerns                                         4




                            Objections / Criticism


    Designed in the 70th and hardly evolved since

      “#ifdef considered harmful”
                                                                  “#ifdef hell”
   “maintenance becomes a ‘hit or miss’ process”

                                          “is difficult to determine if the code being
                                           viewed is actually compiled into the system”

                    “incomprehensible source texts”
     “programming errors are easy                     “CPP makes maintenance difficult”
      to make and difficult to detect”
                                                         “source code rapidly
“preprocessor diagnostics are poor”                       becomes a maze”
Christian Kästner: Virtual Separation of Concerns                                                  5



       Academia: Compositional Approaches

 Base / Platform
   class Stack {
   class Stack {
     void push(Object o) {
     void push(Object o) {
       elementData[size++] = o;
       elementData[size++] = o;
     }
     }
     ...
     ...
   }
   }


                                                                    class Stack {
                                                                    class Stack {
                                                                      void push(Object o) {
                                                                      void push(Object o) {
                                                                        Lock l = lock(o);
 Feature: Queue                                                         Lock l = lock(o);
                                                                        elementData[size++] = o;
                                                                        elementData[size++] = o;
   refines class Stack {
   refines class Stack {
                                                    Composition       }
                                                                      }
                                                                        l.unlock();
                                                                        l.unlock();
                                                                      ...
     void push(Object o) {
     void push(Object o) {                                            ...
       Lock l = lock(o);
       Lock l = lock(o);                                            }
                                                                    }
       Super.push(o);
       Super.push(o);
       l.unlock();
       l.unlock();
     }
     }
     ...
     ...
   }
   }
                                                        Module
                                                        Components
 Feature: Diagnostic                                    Frameworks, Plug-ins
   aspect Diagnostics {
   aspect Diagnostics {
     ...
                                                        Feature-Modules / Mixin Layers / …
     ...
   }
   }                                                    Aspects / Subjects, Hyper/J
Christian Kästner: Virtual Separation of Concerns      6




                                              Agenda

• Problems and Advantages of Preprocessors
• 4 Improvements
      •   Views
      •   Visual Representation
      •   Disciplined Annotations
      •   Product-Line-Aware Type System
• Summary and Perspective
Christian Kästner: Virtual Separation of Concerns   7




Problem 1: Lack of Separation of Concerns

•    Scattered and tangled source code
•    Global search to understand a feature
•    Deleting obsolete feature as challenge
•    Difficult distributed development
•    Difficult reuse



    Beispiel Berkeley DB:
    Feature Sperren mit 1835 LOC
    in 28 von 300 Dateien
    an 155 Stellen
Christian Kästner: Virtual Separation of Concerns                               8




                         Problem 2: Obfuscation

• Mixture of two                                    class Stack {
                                                    class Stack {
                                                        void push(Object o
  languages                                             void push(Object o
                                                    #ifdef SYNC
                                                    #ifdef SYNC
                                                        , Transaction txn
  (C und #ifdef, …)                                     , Transaction txn
                                                    #endif
                                                    #endif
                                                        ) {
• Control flow hard to                                  ) {
                                                            if (o==null
                                                            if (o==null
                                                    #ifdef SYNC
                                                    #ifdef SYNC
  follow                                                        || txn==null
                                                                || txn==null
                                                    #endif
                                                    #endif
• Additional line breaks                                        ) return;
                                                                ) return;
                                                    #ifdef SYNC
                                                    #ifdef SYNC
  destroy code layout                                       Lock l=txn.lock(o);
                                                            Lock l=txn.lock(o);
                                                    #endif
                                                    #endif
• Long annotations                                          elementData[size++] = o;
                                                            elementData[size++] = o;
                                                    #ifdef SYNC
                                                    #ifdef SYNC
  difficult to recognize                                    l.unlock();
                                                            l.unlock();
                                                    #endif
                                                    #endif
                                                            fireStackChanged();
                                                            fireStackChanged();
                                                        }
                                                        }
                                                    }
                                                    }
Christian Kästner: Virtual Separation of Concerns   9




                      Preprocessor in Femto OS
Christian Kästner: Virtual Separation of Concerns                            10




                          Problem 3: Error-Prone

• Syntax Errors                                     • Type Errors
  static int _rep_queue_filedone(...)               #ifdef TABLES
      DB_ENV *dbenv;                                class Table {
      REP *rep;                                       void insert(Object data,
      __rep_fileinfo_args *rfp; {                               Txn txn) {
  #ifndef HAVE_QUEUE                                       storage.set(data,
      COMPQUIET(rep, NULL);                                     txn.getLock());
      COMPQUIET(rfp, NULL);                           }
      return (__db_no_queue_am(dbenv));             }
  #else                                             #endif
      db_pgno_t first, last;                        class Storage {
      u_int32_t flags;                              #ifdef WRITE
      int empty, ret, t_ret;                            boolean set(…) { ... }
  #ifdef DIAGNOSTIC                                 #endif
      DB_MSGBUF mb;                                 }
  #endif
      // over 100 lines of additional code
  }
  #endif
Christian Kästner: Virtual Separation of Concerns                            11




                          Problem 3: Error-Prone

• Syntax Errors                                     • Type Errors
  static int _rep_queue_filedone(...)               #ifdef TABLES
      DB_ENV *dbenv;                                class Table {
      REP *rep;                                       void insert(Object data,
      __rep_fileinfo_args *rfp; {                               Txn txn) {
  #ifndef HAVE_QUEUE                                       storage.set(data,
      COMPQUIET(rep, NULL);                                     txn.getLock());
      COMPQUIET(rfp, NULL);                           }
      return (__db_no_queue_am(dbenv));             }
  #else                                             #endif
      db_pgno_t first, last;                        class Storage {
      u_int32_t flags;                              #ifdef WRITE
      int empty, ret, t_ret;                            boolean set(…) { ... }
  #ifdef DIAGNOSTIC                                 #endif
      DB_MSGBUF mb;                                 }
  #endif
      // over 100 lines of additional code
  }
  #endif
Christian Kästner: Virtual Separation of Concerns                            12




                          Problem 3: Error-Prone

• Syntax Errors                                     • Type Errors
  static int _rep_queue_filedone(...)               #ifdef TABLES
      DB_ENV *dbenv;                                class Table {
      REP *rep;                                       void insert(Object data,
      __rep_fileinfo_args *rfp; {                               Txn txn) {
  #ifndef HAVE_QUEUE                                       storage.set(data,
      COMPQUIET(rep, NULL);                                     txn.getLock());
      COMPQUIET(rfp, NULL);                           }
      return (__db_no_queue_am(dbenv));             }
  #else                                             #endif
      db_pgno_t first, last;                        class Storage {
      u_int32_t flags;                              #ifdef WRITE
      int empty, ret, t_ret;                            boolean set(…) { ... }
  #ifdef DIAGNOSTIC                                 #endif
      DB_MSGBUF mb;                                 }
  #endif
      // over 100 lines of additional code
  }
  #endif
Christian Kästner: Virtual Separation of Concerns       13




                                        Advantages

• Easy to use
      • “annotate and remove”
      • Already part of many languages / simple tools
      • Most developers already familiar


• Flexible / Expressive
• Language-independent / Uniform

• Low Adoption Barrier
      • esp. with legacy code
Christian Kästner: Virtual Separation of Concerns      14




                                              Agenda

• Problems and Advantages of Preprocessors
• 4 Improvements
      •   Views
      •   Visual Representation
      •   Disciplined Annotations
      •   Product-Line-Aware Type System
• Summary and Perspective
Christian Kästner: Virtual Separation of Concerns                                 15

                                                              [ICSE’08, ViSPLE’08]

                                                Views

• Emulate modularity
• Hide irrelevant source code
      • Hides entire files
      • Hides code inside files



                                                        Related work:
                                                        • C-CLR
                                                        • Version Editor
                                                        • FeatureMapper
                                                        • pure::variants
                                                        • Effective Views
                                                        • on-demand remodularization
                                                        …
Christian Kästner: Virtual Separation of Concerns   16




                              Expression Problem
Christian Kästner: Virtual Separation of Concerns   17




                            View on Feature Eval




• Shows all files containing Eval code
• Shows context information (kursiv)
• Hides code without annotations
Christian Kästner: Virtual Separation of Concerns   18




         View on the Variant “Add and Eval”




• Entirely hides file Power
• Hides method print in Add ([…])
• Code without annotation remains visible
Christian Kästner: Virtual Separation of Concerns      19




                                              Agenda

• Problems and Advantages of Preprocessors
• 4 Improvements
      •   Views
      •   Visual Representation
      •   Disciplined Annotations
      •   Product-Line-Aware Type System
• Summary and Perspective
Christian Kästner: Virtual Separation of Concerns                      20

                                                     [ICSE’08, ViSPLE’08]

 Visual Representation: Background Colors

  class Stack {
  class Stack {
      void push(Object o
       void push(Object o
  #ifdef SYNC
  #ifdef SYNC
      , Transaction txn
       , Transaction txn
  #endif
  #endif
      ) {
       ) {
           if (o==null
           if (o==null
  #ifdef SYNC
  #ifdef SYNC
               || txn==null
                || txn==null
  #endif
  #endif
               ) return;
                ) return;
  #ifdef SYNC
  #ifdef SYNC
           Lock l=txn.lock(o);
           Lock l=txn.lock(o);
  #endif
  #endif
           elementData[size++] = o;
           elementData[size++] = o;
  #ifdef SYNC
  #ifdef SYNC                                       Related Work:
           l.unlock();
           l.unlock();
  #endif                                            • Spotlight
  #endif
           fireStackChanged();
           fireStackChanged();                      • NetBeans
      }}                                            • fmp2rsm
  }
  }                                                 • FeatureMapper
                                                    • AspectBrowser
                                                    …
Christian Kästner: Virtual Separation of Concerns                 21




          Alternative Visual Representations

 ● NetBeans                                         ● Spotlight
Christian Kästner: Virtual Separation of Concerns   22




               Scaling Visual Representations

• Focus on few features at a time
• Repeating colors / manual assignment
  sufficient
• Analysis of 4 Java ME and 40 C programs:
      • 96 % pages of source code with ≤ 3 colors
      • 99 % pages of source code with ≤ 7 colors
Christian Kästner: Virtual Separation of Concerns   23




   Program Comprehension: An Experiment

 • #ifdef vs. colors
 • 43 subjects in 2
   groups
 • S1-2: search tasks
   faster with colors
   (43% & 23%)
 • M1-3: maintenance
   tasks same perform.
 • M4: maintenance
   task with red back-
   ground color -37%
 • No influence on correctness
 • Subjects prefer colors
Christian Kästner: Virtual Separation of Concerns      24




                                              Agenda

• Problems and Advantages of Preprocessors
• 4 Improvements
      •   Views
      •   Visual Representation
      •   Disciplined Annotations
      •   Product-Line-Aware Type System
• Summary and Perspective
Christian Kästner: Virtual Separation of Concerns                                   25

                                                                     [TOOLS‘09]

                         Disciplined Annotations
                                                                 class Foo { }
• Syntax errors caused by
  annotations on plain text            class Foo                                 { }

• Solution: Use underlying artifact structure
      • Enforce disciplined annotations on entire classes,
        methods, or statements
      • Annotations of isolated brackets or      ClassDeclaration
                                                     Name=C
        keywords regarded as undisciplined      MethodDeclaration
                                                                     Name=m

                                                    ReturnType   Parameter
           class C {                                 Type-void    Name=p
                                                                                Block
               void m(int p) {
                   s1();
                                                                 MethodInvk   MethodInvk
                   s2(p, true);                                   Name=s1      Name=s2
               }
           }                                                     Parameter    Parameter
                                                                  Name=p      Name=true
Christian Kästner: Virtual Separation of Concerns                                                          26




Variant Generation by AST Transformation
                    ClassDeclaration                                          ClassDeclaration
                        Name=C                                                    Name=C

                   MethodDeclaration
                                                                          MethodDeclaration
                       Name=m
                                                                              Name=m

       ReturnType    Parameter
                                       Block
        Type-void     Name=p                                     ReturnType     Parameter
                                                                                                   Block
                                                                  Type-void      Name=p
                     MethodInvk    MethodInvk
                      Name=s1       Name=s2
                                                      variant                                    MethodInvk
                                                                                                  Name=s1
                     Parameter     Parameter        generation
                      Name=p       Name=true
                                                                                          print /
                               parsing                                                    unparse
            class C {                                                 class C {
                void m(int p) {                                           void m(int p) {
                    s1();                                                     s1();
                    s2(p, true);                                          }
                }                                                     }
            }

                         Variant generation cannot cause syntax errors.
Christian Kästner: Virtual Separation of Concerns                             27




 Expressiveness of Disciplined Annotations

• Not all annotations are possible
• Sometimes workarounds required
• Experience: not a significant restriction in
  practice
• ~90% of all annotations in 40 C programs is
  disciplined already
 high flexibility                                                 no flexibility



unrestricted                  disciplined annotations    classes          no
annotations                     (underlying structure)     only  annotations
on any character
Christian Kästner: Virtual Separation of Concerns      28




                                              Agenda

• Problems and Advantages of Preprocessors
• 4 Improvements
      •   Views
      •   Visual Representation
      •   Disciplined Annotations
      •   Product-Line-Aware Type System
• Summary and Perspective
Christian Kästner: Virtual Separation of Concerns                                        29

                                                                                 [ASE’08]

            Product-Line-Aware Type System
                                                                    class Database {
                                                                      Storage storage;
• Base: Type correct without                                          void insert(Object data
                                                                                Txn txn) {
  annotations (for tool support)                                           storage.set(data,
                                                                                txn.getLock())
• Detecting all pairs:                                                }
                                                                    }
      • Method invocation and                                       class Storage {
                                                                    #ifdef WRITE
        method declaration                                              boolean set(…) { ... }
      • Reference and declaration                                   #endif
                                                                    }
        of class, variable, etc.
      • …                                                               Related Work:
• Comparison of annotations for                                         • SafeGen
                                                                        • fmp2rsm
  each pair                                                             • Safe Composition
                                                                        • FFJPL
  Declaration annotated +                           Error in some       • Conditional
  Reference not annotated                           variants              Methods
Christian Kästner: Virtual Separation of Concerns                               30



                 Type Checking in the Context
                      of a Feature Model
                                                                        ¬Read
• Handling dependencies                             class Database {
  between features                                    void insert(…) {
                                                        storage.set(…);

• Can all variants with
                                                      }
                                                    }
                                                    class Storage {
  reference reach a                                   boolean set(…) { ... }
  corresp. declaration?                             }
                                                                     Write

                                                            FM = API ∧ ( API ⇒
• Implementation: Propositional                                 (read ∨ write))
  logic and SAT solvers:
   In all variants in which code fragment A is
   included also code fragment B is included:
                FM ⇒ ( AT (a ) ⇒ AT (b))
Christian Kästner: Virtual Separation of Concerns          31

                                                     [ASE’08]

                                Formalization: CFJ

 ● On top of Featherweight Java
 ● Theorem: Generation preserves typing
       ● Formal proof with Coq
Christian Kästner: Virtual Separation of Concerns            32




                           Implementation: CIDE




                                       http://fosd.de/cide
Christian Kästner: Virtual Separation of Concerns                           33

                                                                      [GPCE’09]

                         Automated Refactorings

 • Feature Module                                    ● Annotationen
       class Stack {
       class Stack {                     class Stack {
                                         class Stack {
          int[] data;
           int[] data;                       int[] data;
                                             int[] data;
Base




          void push(int o) { … }
           void push(int o) { … }        #ifdef UNDO
                                         #ifdef UNDO
          int pop() { /*...*/ }
           int pop() { /*...*/ }             int backup;
                                             int backup;
       }
       }                                     void undo() { /*...*/ }
                                             void undo() { /*...*/ }
                                         #endif
                                         #endif
       refines class Stack {
       refines class Stack {             #ifdef TOP
                                         #ifdef TOP
                           Automated Transformationtop() { /*...*/ }
Top




          int top() { /*...*/ }
          int top() { /*...*/ }              int top() { /*...*/ }
                                             int
       }
       }                                 #endif
                                         #endif
                                             void push(int o) {
                                             void push(int o) {
       refines class Stack {
       refines class Stack {             #ifdef UNDO
                                         #ifdef UNDO
          int backup;
          int backup;                             backup = top();
                                                  backup = top();
          void undo() { /*...*/ }
          void undo() { /*...*/ }        #endif
                                         #endif
Undo




          void push(int o) {
          void push(int o) {                      /*...*/
                                                  /*...*/
             backup = top();
              backup = top();                }
                                             }
             original(v);
              original(v);                   int pop() { /*...*/ }
                                             int pop() { /*...*/ }
          }
          }                              }
                                         }
Christian Kästner: Virtual Separation of Concerns      34




                                              Agenda

• Problems and Advantages of Preprocessors
• 4 Improvements
      •   Views
      •   Visual Representation
      •   Disciplined Annotations
      •   Product-Line-Aware Type System
• Summary and Perspective
Christian Kästner: Virtual Separation of Concerns                               35




                                            Summary

• Problems:                                         • Improvements:
      • Separation of Concerns                        •   Views
      • Obfuscation                                   •   Visual representation
      • Error-proneness                               •   Disciplined annotations
                                                      •   Product-line-aware type
                                                          system
• Retained advantages:
      •   Easy to use
      •   Flexible
      •   Language-independent
      •   Low adoption barrier

             “Virtual Separation of Concerns”
Christian Kästner: Virtual Separation of Concerns                               36




                                            Summary

• Problems:                                         • Improvements:
      • Separation of Concerns                        •   Views
      • Obfuscation                                   •   Visual representation
      • Error-proneness                               •   Disciplined annotations
                                                      •   Product-line-aware type
                                                          system
• Retained advantages:
      •   Easy to use
      •   Flexible
      •   Language-independent
      •   Low adoption barrier

             “Virtual Separation of Concerns”
Christian Kästner: Virtual Separation of Concerns                               37




                                            Summary

• Problems:                                         • Improvements:
      • Separation of Concerns                        •   Views
      • Obfuscation                                   •   Visual representation
      • Error-proneness                               •   Disciplined annotations
                                                      •   Product-line-aware type
                                                          system
• Retained advantages:
      •   Easy to use                               • Remaining Problems:
      •   Flexible                                    • Separate Compilation
      •   Language-independent                        • Black-box Reuse
      •   Low adoption barrier

             “Virtual Separation of Concerns”
Christian Kästner: Virtual Separation of Concerns     38




                                        Perspective

 • Preprocessors common in practice,
   despite strong criticism
 • Neglected by researchers
 • Tool support can address most problems

 • Interim solution (with migration path) or
   serious alternative?

 • Give preprocessors a second chance!
Christian Kästner: Virtual Separation of Concerns                     39




                                         Questions?




                                                      http://fosd.de/cide

Más contenido relacionado

La actualidad más candente

Scala design pattern
Scala design patternScala design pattern
Scala design patternKenji Yoshida
 
A recommender system for generalizing and refining code templates
A recommender system for generalizing and refining code templatesA recommender system for generalizing and refining code templates
A recommender system for generalizing and refining code templatesCoen De Roover
 
Applicative Logic Meta-Programming as the foundation for Template-based Progr...
Applicative Logic Meta-Programming as the foundation for Template-based Progr...Applicative Logic Meta-Programming as the foundation for Template-based Progr...
Applicative Logic Meta-Programming as the foundation for Template-based Progr...Coen De Roover
 
Dependency Breaking Techniques
Dependency Breaking TechniquesDependency Breaking Techniques
Dependency Breaking Techniqueshyun soomyung
 
Oop04 6
Oop04 6Oop04 6
Oop04 6schwaa
 
Core java concepts
Core java concepts Core java concepts
Core java concepts javeed_mhd
 
Writing Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel SchulhofWriting Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel SchulhofWithTheBest
 
Let's talk about jni
Let's talk about jniLet's talk about jni
Let's talk about jniYongqiang Li
 
Scala overview
Scala overviewScala overview
Scala overviewSteve Min
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
JVM bytecode - The secret language behind Java and Scala
JVM bytecode - The secret language behind Java and ScalaJVM bytecode - The secret language behind Java and Scala
JVM bytecode - The secret language behind Java and ScalaTakipi
 
Fundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسیFundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسیSaman Chitsazian
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеSergey Platonov
 

La actualidad más candente (19)

Project Roslyn: Exposing the C# and VB compiler’s code analysis
Project Roslyn: Exposing the C# and VB compiler’s code analysisProject Roslyn: Exposing the C# and VB compiler’s code analysis
Project Roslyn: Exposing the C# and VB compiler’s code analysis
 
Scala design pattern
Scala design patternScala design pattern
Scala design pattern
 
A recommender system for generalizing and refining code templates
A recommender system for generalizing and refining code templatesA recommender system for generalizing and refining code templates
A recommender system for generalizing and refining code templates
 
Smart Pointers
Smart PointersSmart Pointers
Smart Pointers
 
Applicative Logic Meta-Programming as the foundation for Template-based Progr...
Applicative Logic Meta-Programming as the foundation for Template-based Progr...Applicative Logic Meta-Programming as the foundation for Template-based Progr...
Applicative Logic Meta-Programming as the foundation for Template-based Progr...
 
Dependency Breaking Techniques
Dependency Breaking TechniquesDependency Breaking Techniques
Dependency Breaking Techniques
 
Oop04 6
Oop04 6Oop04 6
Oop04 6
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
Writing Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel SchulhofWriting Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel Schulhof
 
Let's talk about jni
Let's talk about jniLet's talk about jni
Let's talk about jni
 
Scala overview
Scala overviewScala overview
Scala overview
 
Java generics final
Java generics finalJava generics final
Java generics final
 
Javamschn3
Javamschn3Javamschn3
Javamschn3
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
JVM bytecode - The secret language behind Java and Scala
JVM bytecode - The secret language behind Java and ScalaJVM bytecode - The secret language behind Java and Scala
JVM bytecode - The secret language behind Java and Scala
 
Fundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسیFundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسی
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI веке
 

Destacado

Parsing and Type checking all 2^10000 configurations of the Linux kernel
Parsing and Type checking all 2^10000 configurations of the Linux kernelParsing and Type checking all 2^10000 configurations of the Linux kernel
Parsing and Type checking all 2^10000 configurations of the Linux kernelchk49
 
Semseo socialamedier-hr
Semseo socialamedier-hrSemseo socialamedier-hr
Semseo socialamedier-hrPeter Tilling
 
Virtual Separation of Concerns (2011 Update)
Virtual Separation of Concerns (2011 Update)Virtual Separation of Concerns (2011 Update)
Virtual Separation of Concerns (2011 Update)chk49
 
Variability-Aware Parsing -- OOPSLA Talk
Variability-Aware Parsing -- OOPSLA TalkVariability-Aware Parsing -- OOPSLA Talk
Variability-Aware Parsing -- OOPSLA Talkchk49
 
Variability-Aware Analysis (FOSD Dagstuhl 2011)
Variability-Aware Analysis (FOSD Dagstuhl 2011)Variability-Aware Analysis (FOSD Dagstuhl 2011)
Variability-Aware Analysis (FOSD Dagstuhl 2011)chk49
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 

Destacado (7)

Parsing and Type checking all 2^10000 configurations of the Linux kernel
Parsing and Type checking all 2^10000 configurations of the Linux kernelParsing and Type checking all 2^10000 configurations of the Linux kernel
Parsing and Type checking all 2^10000 configurations of the Linux kernel
 
Semseo socialamedier-hr
Semseo socialamedier-hrSemseo socialamedier-hr
Semseo socialamedier-hr
 
Virtual Separation of Concerns (2011 Update)
Virtual Separation of Concerns (2011 Update)Virtual Separation of Concerns (2011 Update)
Virtual Separation of Concerns (2011 Update)
 
Variability-Aware Parsing -- OOPSLA Talk
Variability-Aware Parsing -- OOPSLA TalkVariability-Aware Parsing -- OOPSLA Talk
Variability-Aware Parsing -- OOPSLA Talk
 
Seeing Software
Seeing SoftwareSeeing Software
Seeing Software
 
Variability-Aware Analysis (FOSD Dagstuhl 2011)
Variability-Aware Analysis (FOSD Dagstuhl 2011)Variability-Aware Analysis (FOSD Dagstuhl 2011)
Variability-Aware Analysis (FOSD Dagstuhl 2011)
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Similar a Virtual Separation of Concerns

Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topicsRajesh Verma
 
14.jun.2012
14.jun.201214.jun.2012
14.jun.2012Tech_MX
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part IEugene Lazutkin
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Agora Group
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingGarth Gilmour
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.Brian Hsu
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?Andrey Karpov
 
C interview questions
C interview questionsC interview questions
C interview questionsSoba Arjun
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And AnswerJagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
Scala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosScala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosGenevaJUG
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaBrian Hsu
 
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)Theo Jungeblut
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vectornurkhaledah
 
Clean Code for East Bay .NET User Group
Clean Code for East Bay .NET User GroupClean Code for East Bay .NET User Group
Clean Code for East Bay .NET User GroupTheo Jungeblut
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 

Similar a Virtual Separation of Concerns (20)

Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
 
14.jun.2012
14.jun.201214.jun.2012
14.jun.2012
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.
 
core java
core javacore java
core java
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
F#3.0
F#3.0 F#3.0
F#3.0
 
C interview questions
C interview questionsC interview questions
C interview questions
 
обзор Python
обзор Pythonобзор Python
обзор Python
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Scala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosScala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian Dragos
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
 
Clean Code for East Bay .NET User Group
Clean Code for East Bay .NET User GroupClean Code for East Bay .NET User Group
Clean Code for East Bay .NET User Group
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 

Último

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 

Último (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

Virtual Separation of Concerns

  • 1. Photo (cc) Horia Varlan Virtual Separation of Concerns Toward preprocessors 2.0 Christian Kästner
  • 2. Christian Kästner: Virtual Separation of Concerns 2 Software Product Lines & Features • Set of related software systems (variants) in a domain • Generated from common code base • Variants distinguished in terms of features
  • 3. Christian Kästner: Virtual Separation of Concerns 3 Conditional Compilation with Preprocessors ● Annotated code static int _rep_queue_filedone(... DB_ENV *dbenv; fragments REP *rep; __rep_fileinfo_args *rfp; { ● Variants with and #ifndef HAVE_QUEUE COMPQUIET(rep, NULL); without features COMPQUIET(rfp, NULL); return (__db_no_queue_am(dbenv #else db_pgno_t first, last; ● Common for product- u_int32_t flags; int empty, ret, t_ret; line implementation #ifdef DIAGNOSTIC DB_MSGBUF mb; in industry #endif ... Excerpt from Oracle’s Berkeley DB Preprocessors in C, C++, Java ME, Pascal, Erlang, C#, Visual Basic, … GPP, GNU M4, SPLET, Frames/XVCL, Gears, pure::variants
  • 4. Christian Kästner: Virtual Separation of Concerns 4 Objections / Criticism Designed in the 70th and hardly evolved since “#ifdef considered harmful” “#ifdef hell” “maintenance becomes a ‘hit or miss’ process” “is difficult to determine if the code being viewed is actually compiled into the system” “incomprehensible source texts” “programming errors are easy “CPP makes maintenance difficult” to make and difficult to detect” “source code rapidly “preprocessor diagnostics are poor” becomes a maze”
  • 5. Christian Kästner: Virtual Separation of Concerns 5 Academia: Compositional Approaches Base / Platform class Stack { class Stack { void push(Object o) { void push(Object o) { elementData[size++] = o; elementData[size++] = o; } } ... ... } } class Stack { class Stack { void push(Object o) { void push(Object o) { Lock l = lock(o); Feature: Queue Lock l = lock(o); elementData[size++] = o; elementData[size++] = o; refines class Stack { refines class Stack { Composition } } l.unlock(); l.unlock(); ... void push(Object o) { void push(Object o) { ... Lock l = lock(o); Lock l = lock(o); } } Super.push(o); Super.push(o); l.unlock(); l.unlock(); } } ... ... } } Module Components Feature: Diagnostic Frameworks, Plug-ins aspect Diagnostics { aspect Diagnostics { ... Feature-Modules / Mixin Layers / … ... } } Aspects / Subjects, Hyper/J
  • 6. Christian Kästner: Virtual Separation of Concerns 6 Agenda • Problems and Advantages of Preprocessors • 4 Improvements • Views • Visual Representation • Disciplined Annotations • Product-Line-Aware Type System • Summary and Perspective
  • 7. Christian Kästner: Virtual Separation of Concerns 7 Problem 1: Lack of Separation of Concerns • Scattered and tangled source code • Global search to understand a feature • Deleting obsolete feature as challenge • Difficult distributed development • Difficult reuse Beispiel Berkeley DB: Feature Sperren mit 1835 LOC in 28 von 300 Dateien an 155 Stellen
  • 8. Christian Kästner: Virtual Separation of Concerns 8 Problem 2: Obfuscation • Mixture of two class Stack { class Stack { void push(Object o languages void push(Object o #ifdef SYNC #ifdef SYNC , Transaction txn (C und #ifdef, …) , Transaction txn #endif #endif ) { • Control flow hard to ) { if (o==null if (o==null #ifdef SYNC #ifdef SYNC follow || txn==null || txn==null #endif #endif • Additional line breaks ) return; ) return; #ifdef SYNC #ifdef SYNC destroy code layout Lock l=txn.lock(o); Lock l=txn.lock(o); #endif #endif • Long annotations elementData[size++] = o; elementData[size++] = o; #ifdef SYNC #ifdef SYNC difficult to recognize l.unlock(); l.unlock(); #endif #endif fireStackChanged(); fireStackChanged(); } } } }
  • 9. Christian Kästner: Virtual Separation of Concerns 9 Preprocessor in Femto OS
  • 10. Christian Kästner: Virtual Separation of Concerns 10 Problem 3: Error-Prone • Syntax Errors • Type Errors static int _rep_queue_filedone(...) #ifdef TABLES DB_ENV *dbenv; class Table { REP *rep; void insert(Object data, __rep_fileinfo_args *rfp; { Txn txn) { #ifndef HAVE_QUEUE storage.set(data, COMPQUIET(rep, NULL); txn.getLock()); COMPQUIET(rfp, NULL); } return (__db_no_queue_am(dbenv)); } #else #endif db_pgno_t first, last; class Storage { u_int32_t flags; #ifdef WRITE int empty, ret, t_ret; boolean set(…) { ... } #ifdef DIAGNOSTIC #endif DB_MSGBUF mb; } #endif // over 100 lines of additional code } #endif
  • 11. Christian Kästner: Virtual Separation of Concerns 11 Problem 3: Error-Prone • Syntax Errors • Type Errors static int _rep_queue_filedone(...) #ifdef TABLES DB_ENV *dbenv; class Table { REP *rep; void insert(Object data, __rep_fileinfo_args *rfp; { Txn txn) { #ifndef HAVE_QUEUE storage.set(data, COMPQUIET(rep, NULL); txn.getLock()); COMPQUIET(rfp, NULL); } return (__db_no_queue_am(dbenv)); } #else #endif db_pgno_t first, last; class Storage { u_int32_t flags; #ifdef WRITE int empty, ret, t_ret; boolean set(…) { ... } #ifdef DIAGNOSTIC #endif DB_MSGBUF mb; } #endif // over 100 lines of additional code } #endif
  • 12. Christian Kästner: Virtual Separation of Concerns 12 Problem 3: Error-Prone • Syntax Errors • Type Errors static int _rep_queue_filedone(...) #ifdef TABLES DB_ENV *dbenv; class Table { REP *rep; void insert(Object data, __rep_fileinfo_args *rfp; { Txn txn) { #ifndef HAVE_QUEUE storage.set(data, COMPQUIET(rep, NULL); txn.getLock()); COMPQUIET(rfp, NULL); } return (__db_no_queue_am(dbenv)); } #else #endif db_pgno_t first, last; class Storage { u_int32_t flags; #ifdef WRITE int empty, ret, t_ret; boolean set(…) { ... } #ifdef DIAGNOSTIC #endif DB_MSGBUF mb; } #endif // over 100 lines of additional code } #endif
  • 13. Christian Kästner: Virtual Separation of Concerns 13 Advantages • Easy to use • “annotate and remove” • Already part of many languages / simple tools • Most developers already familiar • Flexible / Expressive • Language-independent / Uniform • Low Adoption Barrier • esp. with legacy code
  • 14. Christian Kästner: Virtual Separation of Concerns 14 Agenda • Problems and Advantages of Preprocessors • 4 Improvements • Views • Visual Representation • Disciplined Annotations • Product-Line-Aware Type System • Summary and Perspective
  • 15. Christian Kästner: Virtual Separation of Concerns 15 [ICSE’08, ViSPLE’08] Views • Emulate modularity • Hide irrelevant source code • Hides entire files • Hides code inside files Related work: • C-CLR • Version Editor • FeatureMapper • pure::variants • Effective Views • on-demand remodularization …
  • 16. Christian Kästner: Virtual Separation of Concerns 16 Expression Problem
  • 17. Christian Kästner: Virtual Separation of Concerns 17 View on Feature Eval • Shows all files containing Eval code • Shows context information (kursiv) • Hides code without annotations
  • 18. Christian Kästner: Virtual Separation of Concerns 18 View on the Variant “Add and Eval” • Entirely hides file Power • Hides method print in Add ([…]) • Code without annotation remains visible
  • 19. Christian Kästner: Virtual Separation of Concerns 19 Agenda • Problems and Advantages of Preprocessors • 4 Improvements • Views • Visual Representation • Disciplined Annotations • Product-Line-Aware Type System • Summary and Perspective
  • 20. Christian Kästner: Virtual Separation of Concerns 20 [ICSE’08, ViSPLE’08] Visual Representation: Background Colors class Stack { class Stack { void push(Object o void push(Object o #ifdef SYNC #ifdef SYNC , Transaction txn , Transaction txn #endif #endif ) { ) { if (o==null if (o==null #ifdef SYNC #ifdef SYNC || txn==null || txn==null #endif #endif ) return; ) return; #ifdef SYNC #ifdef SYNC Lock l=txn.lock(o); Lock l=txn.lock(o); #endif #endif elementData[size++] = o; elementData[size++] = o; #ifdef SYNC #ifdef SYNC Related Work: l.unlock(); l.unlock(); #endif • Spotlight #endif fireStackChanged(); fireStackChanged(); • NetBeans }} • fmp2rsm } } • FeatureMapper • AspectBrowser …
  • 21. Christian Kästner: Virtual Separation of Concerns 21 Alternative Visual Representations ● NetBeans ● Spotlight
  • 22. Christian Kästner: Virtual Separation of Concerns 22 Scaling Visual Representations • Focus on few features at a time • Repeating colors / manual assignment sufficient • Analysis of 4 Java ME and 40 C programs: • 96 % pages of source code with ≤ 3 colors • 99 % pages of source code with ≤ 7 colors
  • 23. Christian Kästner: Virtual Separation of Concerns 23 Program Comprehension: An Experiment • #ifdef vs. colors • 43 subjects in 2 groups • S1-2: search tasks faster with colors (43% & 23%) • M1-3: maintenance tasks same perform. • M4: maintenance task with red back- ground color -37% • No influence on correctness • Subjects prefer colors
  • 24. Christian Kästner: Virtual Separation of Concerns 24 Agenda • Problems and Advantages of Preprocessors • 4 Improvements • Views • Visual Representation • Disciplined Annotations • Product-Line-Aware Type System • Summary and Perspective
  • 25. Christian Kästner: Virtual Separation of Concerns 25 [TOOLS‘09] Disciplined Annotations class Foo { } • Syntax errors caused by annotations on plain text class Foo { } • Solution: Use underlying artifact structure • Enforce disciplined annotations on entire classes, methods, or statements • Annotations of isolated brackets or ClassDeclaration Name=C keywords regarded as undisciplined MethodDeclaration Name=m ReturnType Parameter class C { Type-void Name=p Block void m(int p) { s1(); MethodInvk MethodInvk s2(p, true); Name=s1 Name=s2 } } Parameter Parameter Name=p Name=true
  • 26. Christian Kästner: Virtual Separation of Concerns 26 Variant Generation by AST Transformation ClassDeclaration ClassDeclaration Name=C Name=C MethodDeclaration MethodDeclaration Name=m Name=m ReturnType Parameter Block Type-void Name=p ReturnType Parameter Block Type-void Name=p MethodInvk MethodInvk Name=s1 Name=s2 variant MethodInvk Name=s1 Parameter Parameter generation Name=p Name=true print / parsing unparse class C { class C { void m(int p) { void m(int p) { s1(); s1(); s2(p, true); } } } } Variant generation cannot cause syntax errors.
  • 27. Christian Kästner: Virtual Separation of Concerns 27 Expressiveness of Disciplined Annotations • Not all annotations are possible • Sometimes workarounds required • Experience: not a significant restriction in practice • ~90% of all annotations in 40 C programs is disciplined already high flexibility no flexibility unrestricted disciplined annotations classes no annotations (underlying structure) only annotations on any character
  • 28. Christian Kästner: Virtual Separation of Concerns 28 Agenda • Problems and Advantages of Preprocessors • 4 Improvements • Views • Visual Representation • Disciplined Annotations • Product-Line-Aware Type System • Summary and Perspective
  • 29. Christian Kästner: Virtual Separation of Concerns 29 [ASE’08] Product-Line-Aware Type System class Database { Storage storage; • Base: Type correct without void insert(Object data Txn txn) { annotations (for tool support) storage.set(data, txn.getLock()) • Detecting all pairs: } } • Method invocation and class Storage { #ifdef WRITE method declaration boolean set(…) { ... } • Reference and declaration #endif } of class, variable, etc. • … Related Work: • Comparison of annotations for • SafeGen • fmp2rsm each pair • Safe Composition • FFJPL Declaration annotated + Error in some • Conditional Reference not annotated variants Methods
  • 30. Christian Kästner: Virtual Separation of Concerns 30 Type Checking in the Context of a Feature Model ¬Read • Handling dependencies class Database { between features void insert(…) { storage.set(…); • Can all variants with } } class Storage { reference reach a boolean set(…) { ... } corresp. declaration? } Write FM = API ∧ ( API ⇒ • Implementation: Propositional (read ∨ write)) logic and SAT solvers: In all variants in which code fragment A is included also code fragment B is included: FM ⇒ ( AT (a ) ⇒ AT (b))
  • 31. Christian Kästner: Virtual Separation of Concerns 31 [ASE’08] Formalization: CFJ ● On top of Featherweight Java ● Theorem: Generation preserves typing ● Formal proof with Coq
  • 32. Christian Kästner: Virtual Separation of Concerns 32 Implementation: CIDE http://fosd.de/cide
  • 33. Christian Kästner: Virtual Separation of Concerns 33 [GPCE’09] Automated Refactorings • Feature Module ● Annotationen class Stack { class Stack { class Stack { class Stack { int[] data; int[] data; int[] data; int[] data; Base void push(int o) { … } void push(int o) { … } #ifdef UNDO #ifdef UNDO int pop() { /*...*/ } int pop() { /*...*/ } int backup; int backup; } } void undo() { /*...*/ } void undo() { /*...*/ } #endif #endif refines class Stack { refines class Stack { #ifdef TOP #ifdef TOP Automated Transformationtop() { /*...*/ } Top int top() { /*...*/ } int top() { /*...*/ } int top() { /*...*/ } int } } #endif #endif void push(int o) { void push(int o) { refines class Stack { refines class Stack { #ifdef UNDO #ifdef UNDO int backup; int backup; backup = top(); backup = top(); void undo() { /*...*/ } void undo() { /*...*/ } #endif #endif Undo void push(int o) { void push(int o) { /*...*/ /*...*/ backup = top(); backup = top(); } } original(v); original(v); int pop() { /*...*/ } int pop() { /*...*/ } } } } }
  • 34. Christian Kästner: Virtual Separation of Concerns 34 Agenda • Problems and Advantages of Preprocessors • 4 Improvements • Views • Visual Representation • Disciplined Annotations • Product-Line-Aware Type System • Summary and Perspective
  • 35. Christian Kästner: Virtual Separation of Concerns 35 Summary • Problems: • Improvements: • Separation of Concerns • Views • Obfuscation • Visual representation • Error-proneness • Disciplined annotations • Product-line-aware type system • Retained advantages: • Easy to use • Flexible • Language-independent • Low adoption barrier “Virtual Separation of Concerns”
  • 36. Christian Kästner: Virtual Separation of Concerns 36 Summary • Problems: • Improvements: • Separation of Concerns • Views • Obfuscation • Visual representation • Error-proneness • Disciplined annotations • Product-line-aware type system • Retained advantages: • Easy to use • Flexible • Language-independent • Low adoption barrier “Virtual Separation of Concerns”
  • 37. Christian Kästner: Virtual Separation of Concerns 37 Summary • Problems: • Improvements: • Separation of Concerns • Views • Obfuscation • Visual representation • Error-proneness • Disciplined annotations • Product-line-aware type system • Retained advantages: • Easy to use • Remaining Problems: • Flexible • Separate Compilation • Language-independent • Black-box Reuse • Low adoption barrier “Virtual Separation of Concerns”
  • 38. Christian Kästner: Virtual Separation of Concerns 38 Perspective • Preprocessors common in practice, despite strong criticism • Neglected by researchers • Tool support can address most problems • Interim solution (with migration path) or serious alternative? • Give preprocessors a second chance!
  • 39. Christian Kästner: Virtual Separation of Concerns 39 Questions? http://fosd.de/cide