IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro...

37
IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira University of Minho, Department of Informatics Nuno Oliveira

Transcript of IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro...

Page 1: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES

Supervisors:

Professor Pedro Rangel Henriques

Professora Maria João Varanda Pereira

University of Minho, Department of Informatics

Nuno Oliveira

Page 2: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

Imagine the following scenario:

2

You are a software analyst…

…who is assigned a task of maintaining a software piece

Page 3: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

3

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;

}}

}

Page 4: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

Your first reaction…

4

And this would be the second one…

- What does this program do?- What are its effects on the real world concepts?

- What is it all about?

- I Can’t even figure out the problem domain!

So you’d probably give up on maintaining such code.

Page 5: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

5

Robots are picking stones, but their

arms never go back down, after the first

stone!

Boss You

Ah, Ok! Let me see it

again.

But… what if, somehow, you have information about the problem domain?

Page 6: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

6

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…

Page 7: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

7

Then…

Program Comprehension (PC) tools (PCTools) will fasten the way you work…

JIRiSS Imagix4D

DA4Java

CodeCrawlerCerberus

BauhausAlma

AlborzSeeSoft

Rigi

Reflexion Model

PICSSHriMP

Page 8: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

8

You will not be able to easily know what statement do what in the real world objects…

And…

Do not take advantage of Problem Domain

Do not connect Problem and Program Domains automatically

So…

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

That is the HARDEST

part!!

Page 9: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

9

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!

Would it be the same with Domain-Specific Languages?

Why?

Page 10: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

Well, imagine again the same scenario:

10

You are a software analyst…

…who is assigned a task of maintaining a software piece

Page 11: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

11

… and that software was developed with a DSL:

PROGRAM {TURN_ONWHILE (TURNED_ON){

IF(HAS_STONE_IN_FRONT){ROBOT_ARM_ON;PICK_STONE;DROP_STONE_IN_BAG;

}}

}

Page 12: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

Your first reaction…

12

- What does this program do?- What are its effects on the real world concepts?

- Is that all?

- 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…

And this would be the second reaction…

Page 13: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

13

Do I need to tell you where the error is?

Boss You

No, boss! Already found it!

Yes, that was easy, but… what if

the DSL is more complex?

A PCTool improved to cope

with DSL advantages would

help us!Is it

possible?

Page 14: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

14

If we prove the following three things:

Page 15: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

15

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

Page 16: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

16

ALMA

- A system to assist program comprehension tasks for ANY GPL

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

The DAST stores the meaning of the program by using semantic patterns as nodes of a tree!

The Meaning?

TEC

HN

IQU

ES

Page 17: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

17

So, to cope with Problem Domain…

ALMA IR needs to be improved…

… adding on, to the semantic patterns:

represent the Problem Domain Concepts Actors

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

Animation Functions

Resulting in…

Page 18: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

18

represent the animation, at problem domain level, according to the operational semantic of the program

Animation Patterns

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

Page 19: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

19

The DAST technique was used in a PCTool

for GPLs…

Boss You

… and can be added of Animation Patterns to cope with Problem Domain Concepts!

Which are static for every

statement in a DSL, regardless of

the program…

So, this answers

question 1!

Page 20: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

20

Page 21: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

21

Evolution: ALMA

Page 22: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

22

Evolution: ALMA >> ALMA2

Page 23: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

23

Beautiful… but how we specify a front-end for

ALMA2 ?

Boss

Page 24: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

24

1. Analyse DSL formal definition and its specific domain

DSL Formal Definition DSL Problem Domain

Program Domain ConceptsProblem Domain Concepts

Possible Internal State

Designing the Problem Visualization by Domains Analysis

Page 25: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

25

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

Program Domain Concepts Problem Domain Concepts

Conceptual Mappings Table

Designing the Problem Visualization by Concepts Mappings Definition

Page 26: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

26

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

Problem Domain Concepts Images

Behavioural Visualization Table

Designing the Problem Visualization by Images and Concepts Association

Page 27: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

27

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

Conceptual Mappings Table Behavioural Visualization Table

Alma2 Front-End for DSPs

Designing the Problem Visualization by Definition of ALMA2 Specification

Theory is good, what about practice?

Page 28: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

28

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

=

a %

+ 360

a 90

Rotate

Label

For each grammar rule we define1. The Operational Semantics using ALMA2 basic API and2. The Operational Behaviour using ALMA2 extended API

Page 29: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

29

ALMA2 tested with Imperative DSL

Page 30: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

30

ALMA2 tested with Declarative DSL

Page 31: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

31

The improvement of ALMA to ALMA2 is

possible…

Boss You

… and the animation of the Problem Domain concepts

together with the visualization of program

domain, is a better perspective for the users!

We can only be sure of its

usefulness if we prove it…

Let’s prove it then!

Page 32: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

32

Extended Brooks TheoryA 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.

Page 33: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

33

The Proof Ingredients:

20 Participants 1 Questionnaire (8 Questions)

The Proof Objectives:

Compare variables measured both in Alma and Alma2

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)

Page 34: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

34

Time

Correctness

Relevance

The Proof Results:

Page 35: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

35

Despite of spending more time to create a mental model of

the program…

Boss You

So, maintenance

time and expenditures are reduced!

…With this approach, the

effectiveness of the

comprehension is achieved…Meaning that synchronized

Visualizations of Prog. And Prob. Domains

are important to achieve the

comprehension of the program

Conclusion

Page 36: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

36

Because the connection of both domains allows us

to:

Boss You

-Perceive how the program does;- Perceive what are the effects of the program in the problem domain…

Conclusion

And of course, to achieve knowledge through an

Action-Effect paradigm.

Page 37: IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES Supervisors: Professor Pedro Rangel Henriques Professora Maria João Varanda Pereira.

IMPROVING PROGRAM COMPREHENSION TOOLS FOR DOMAIN-SPECIFIC LANGUAGES

Thank you!!

University of Minho, Department of Informatics

Nuno Oliveira