Docstoc

IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES

Document Sample
IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Powered By Docstoc
					   IMPROVING PROGRAM
COMPREHENSION TOOLS FOR
DOMAIN-SPECIFIC LANGUAGES

                                 Nuno Oliveira

     Supervisors:
     Professor Pedro Rangel Henriques
     Professora Maria João Varanda Pereira

                     University of Minho,
                     Department of Informatics
Imagine the following scenario:




       You are a software analyst…




…who is assigned a task of maintaining a software piece




                                                          1
Well… this is just a part of that software…

  void fn()
  {
        struct model *o = (struct model *)malloc(sizeof(struct model));
        o->switch = true;
        while(o->switch){
             try_sense(o);
             if(o->sensor_date != NULL){
                   o->p ++;
                   o->h = 1;
                   o->b = (struct object*)malloc(sizeof(struct object));
                   o->b = o->sensor_date;
                   o->sensor_date = NULL;
                   o->b->next = NULL;
             }
        }
  }




                                                                           2
                                 - What is it all about?
Your first reaction…
                                 - What does this program do?
                                 - What are its effects on the real
                                 world concepts?




                 And this would be the second one…
                 - I Can’t even figure out the problem domain!




        So you’d probably give up on maintaining such code.       3
    But… what if, somehow, you have information
           about the problem domain?


 Robots are picking
  stones, but their
arms never go back
down, after the first               Ah, Ok! Let
       stone!                        me see it
                                      again.




          Boss                       You

                                                  4
In fact, this code can solve a lot of problems, and
                 none in particular
 void fn()
 {
       struct model *o = (struct model *)malloc(sizeof(struct model));
       o->switch = true;
       while(o->switch){
            try_sense(o);
            if(o->sensor_date != NULL){
                  o->p ++;
                  o->h = 1;
                  o->b = (struct object*)malloc(sizeof(struct object));
                  o->b = o->sensor_date;
                  o->sensor_date = NULL;
                  o->b->next = NULL;
            }
       }
 }


But if you know that this code corresponds to a
                 robot task…                    5
Then…
Program Comprehension (PC) tools (PCTools) will fasten the way
you work…
                                  DA4Java
                     PICS
                                 SHriMP     Alma    Imagix4D
                 JIRiSS
        Reflexion Model
                            Alborz      Bauhaus
                            CodeCrawler         SeeSoft

                          Rigi       Cerberus




                                                                 6
And…
Do not take advantage of Problem Domain

Do not connect Problem and Program Domains automatically
               You will not be able to easily know what
            statement do what in the real world objects…




So…
Maintenance main tasks are still hand-made, increasing time and
expenditures!



                                                              7
Brooks theorizes that:

 A program is better understood if the person who is through the process of
 comprehension knows the program and problem domains, and is capable of
 establishing bridges between them.



  To formalize such theory in a tool for General Purpose Languages
      (GPL) is impossible or, at least, is neither easy nor direct!


                                           Why?




     Would it be the same with Domain-Specific Languages?
                                                                              8
Well, imagine again the same scenario:




        You are a software analyst…




…who is assigned a task of maintaining a software piece




                                                          9
… and that software was developed with a DSL:



            PROGRAM {
                TURN_ON
                WHILE (TURNED_ON){
                    IF(HAS_STONE_IN_FRONT){
                         ROBOT_ARM_ON;
                         PICK_STONE;
                         DROP_STONE_IN_BAG;
                    }
                }
            }




                                                10
                                 - Is that all?
Your first reaction…
                                 - What does this program do?
                                 - What are its effects on the real
                                 world concepts?




                  And this would be the second reaction…
                  - We’re talking about a robot task…
                  - First, the robot is started, then, in a loop,
                  it picks stones into a bag, whenever it
                  senses one…




                                                                  11
 Do I need to
tell you where                     No, boss!
 the error is?                     Already
                                   found it!
           Yes, that was easy,
            but… what if the
              DSL is more
                complex?            A PCTool improved
                                     to cope with DSL
                                     advantages would
                 Is it possible?          help us!




            Boss                     You

                                                        12
 If we prove the following three things:

Question1:
Can the PC techniques, tailored for GPLs, be applied on DSLs?




            Question2
            Is it possible to improve existent PCTools, in order to give the end-user
            useful and better perspectives to comprehend the program and the
            problem?


Extended Brooks Theory
A program comprehension tool, eases the task of comprehending a program
when synchronized visualizations of its program and problem domains are
provided, since from these visualizations, the user is able to build a
conceptual knowledge base that easily bridges both program and problem
domains.                                                                          13
Can the PC techniques, tailored for GPLs, be applied on DSLs?




                                                                14
 ALMA
    - A system to assist program comprehension tasks for ANY GPL

              DAST – Decorated Abstract Syntax Tree
                (ALMA internal representation (IR) )
TECHNIQUES




The DAST stores the meaning of                   The Meaning?
                                                                   15
the program by using semantic
patterns as nodes of a tree!
So, to cope with Problem Domain…
   ALMA IR needs to be improved…
       … adding on, to the semantic patterns:



        Actors
          represent the Problem Domain Concepts



        Animation Functions
            describe the behavior of the concepts according to
            the operational semantic of the program.



                      Resulting in…                              16
     Animation Patterns
          represent the animation, at problem
          domain level, according to the operational
          semantic of the program


    Are injected in the DAST, creating a DAPAST
(Decorated with Animation Patterns Abstract Syntax Tree)




                                                           17
The DAST technique
was used in a PCTool
     for GPLs…
 … and can be added of
 Animation Patterns to
                         Which are static for
  cope with Problem
                         every statement in
  Domain Concepts!
                         a DSL, regardless
                          of the program…

                               So, this answers
                                 question 1!



          Boss               You

                                                  18
Is it possible to improve existent PCTools, in order to give the
end-user useful and better perspectives to comprehend the
program and the problem?




                                                               19
Evolution: ALMA




                  20
Evolution: ALMA >> ALMA2




                           21
Beautiful… but how we
specify a front-end for
       ALMA2 ?




  Boss

                          22
      Designing the Problem Visualization by
               Domains Analysis



DSL Formal Definition                             DSL Problem Domain




1. Analyse DSL formal definition and its specific domain




      Program Domain Concepts          Problem Domain Concepts

                        Possible Internal State
                                                                       23
            Designing the Problem Visualization by
              Concepts Mappings Definition



Program Domain Concepts                     Problem Domain Concepts




 2. Define mappings between the problem concepts and syntactic or
                    semantic parts of the DSL;




                      Conceptual Mappings Table
                                                                      24
            Designing the Problem Visualization by
             Images and Concepts Association



Problem Domain Concepts                                     Images




3. Associate images or image sequences with concepts at problem domain;




                          Behavioural Visualization Table
                                                                     25
             Designing the Problem Visualization by
             Definition of ALMA2 Specification



Conceptual Mappings Table                    Behavioural Visualization Table




    4. Use Alma2 to build the mappings between problem and program
                           domains and the imagery.




                        Alma2 Front-End for DSPs          Theory is good,
                                                            what about
                                                                               26
                                                             practice?
  For each grammar rule we define
  1. The Operational Semantics using ALMA2 basic API and
  2. The Operational Behaviour using ALMA2 extended API


rule Instruction_TurnLeft {
  INSTRUCTION ::= #Turnleft compute {                              Rotate
    INSTRUCTION.tree =
      new Alma.CStmtsNode(                                 =
                                                                         Label
        new AnimAssignNode(
          tA,                                         a         %
          new Alma.COperNode(
            new Alma.COperNode(
              new Alma.CVarNode(tA),
                                                           +            360
              new Alma.CConstNode(90),
              "+”
            ),                                       a          90
            new Alma.CConstNode(360), "%"),
            new AnimationPattern[] {
              new APRotate(robot, new int[] {1}, "angle"),
              new APLabel(robot, new int[] {1}, "beepers: ", "beepers")
            }
          )                                                                      27
        );
    };
 }
ALMA2 tested with Imperative DSL




                                   28
ALMA2 tested with Declarative DSL




                                    29
The improvement of
ALMA to ALMA2 is
     possible…
  … and the animation of the
  Problem Domain concepts
together with the visualization   We can only be
of program domain, is a better       sure of its
  perspective for the users!      usefulness if we
                                     prove it…
                  Let’s
                 prove it
                  then!



          Boss                    You

                                                     30
Extended Brooks Theory
A program comprehension tool, will ease the task of comprehending a
program when synchronized visualizations of its program and
problem domains are provided, since from these visualizations, the
user is able to build a conceptual knowledge base that easily bridges
both program and problem domains.




                                                                    31
The Proof Ingredients:




        20 Participants              1 Questionnaire (8 Questions)

 The Proof Objectives:
  Solve PC tasks using Alma and Alma2
  Measure variables with the questions:

        Time (spent in the questions)
        Correctness (in the answers)
        Relevance assigned to the approach (of the synchronized
        visualizations)
  Compare variables measured both in Alma and Alma2
                                                                     32
The Proof Results:




                     33
                        Conclusion
 Despite of spending
more time to create a
                                      …With this
 mental model of the
                                    approach, the
     program…
                                   effectiveness of
                                 the comprehension
     So, maintenance                is achieved…
         time and
                                       Meaning that
     expenditures are
                                       synchronized
         reduced!
                                  Visualizations of Prog.
                                  And Prob. Domains are
                                   important to achieve
                                  the comprehension of
                                        the program


          Boss                 You

                                                            34
                     Conclusion
   Because the
connection of both
domains allows us
       to:
           -Perceive how the program does;
         - Perceive what are the effects of the
           program in the problem domain…

                            And of course, to achieve
                              knowledge through an
                             Action-Effect paradigm.




         Boss                 You

                                                        35
   IMPROVING PROGRAM
COMPREHENSION TOOLS FOR
DOMAIN-SPECIFIC LANGUAGES

                               Nuno Oliveira

     Thank you!!




                   University of Minho,
                   Department of Informatics

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:6
posted:7/1/2012
language:Latin
pages:37