14/03/2013

Welcome to SENG 371 Announcements Software Evolution  Lab attendance Spring 2013 ◦ Has been a problem as of late — needs to change ◦ Several questions on labs on final exam  Final exam A Core Course of the BSEng Program ◦ Sat, April 13 — 7:00 -10:00 pm  Marking Hausi A. Müller, PhD PEng ◦ Midterm and A1 graded Professor, Department of ◦ Marks posted  Course website Associate Dean Research, Faculty of Engineering ◦ http://www.engr.uvic.ca/~seng371 University of Victoria ◦ Lecture notes posted ◦ Lab slides and activities are posted  Assignment 3 ◦ Due Thu, April 4 ◦ Cite your sources ◦ Submit by e-mail to [email protected]

2

Reading Assignment Views: Separation of concerns

 Murphy, Notkin, Lan: An empirical study of static call graph  Interfaces extractors, ACM Transactions on Software Engineering and Methodology  Electrical diagrams (TOSEM) 7(2):158-191 (1998)  APIs  Plumbing diagrams ◦ http://dl.acm.org/citation.cfm?id=279314  COTS,   Müller, Jahnke, Smith, Storey, Tilley, Wong: Reverse Engineering: A Perspective views  Scripting layers Roadmap, in The Future of Software Engineering, pp. 47-60 (2000)  Front, top, side views ◦ http://dl.acm.org/citation.cfm?id=336526  Extensibility,  Levels of indirection  Storey: Theories, tools and research methods in program genericity comprehension: past, present and future, Journal  Event handling  Autonomic manager 14:187-208 (2006) versus managed ◦ http://webhome.cs.uvic.ca/~chisel/pubs/storey-pc-journal.pdf  Performance element  Brown, Malveau, McCormick III, Mowbray: AntiPatterns: Refactoring  Platforms, product Software, Architectures, and Projects in Crisis, John Wiley (1998) lines  AntiPatternsTutorial and Website ◦ http://www.antipatterns.com/briefing/index.htm  Persistence, storage ◦ http://www.antipatterns.com

3 4

Views: Separation of Concerns Views: Design Patterns

 UI, DB,  Iterator  Wrapper façade  Data structures  Monitor  Fire walls  Event handling patterns  Security architecture  Mediator  Collection, container  Middleware components  MVC (Model, View, Controller)  Different platforms (i.e., OS)  Serialization  Exception, error handling  Platform dependent/independent parts  Algorithms and data structures

5 6

1 14/03/2013

Program understanding Views: Architecture Patterns Learning objectives  Architectural styles  Learn different models of program  Event driven architecture (event handling) understanding  Pipes and filters  Understand implications of the models on  Publish – subscribe how we write programs and how we use and design maintenance tools

7

Program understanding Overview

 What strategies do you follow when  Program comprehension models trying to understand a program written ◦ Bottom up by someone else? ◦ To p d o w n  Describe the kinds of information you ◦ Integrated meta-model use to arrive at an understanding of ◦ Opportunistic, Systematic etc. how it works.  Theories about tool support ◦ Cognitive support ◦ Improving flow

9 10

Different kinds of models What does this code remind you of?

 A mental model describes the maintainer’s mental representation of the m := (x + y) div 2; program to be understood  A cognitive model describes the processes and information structures used to form the mental model

11

2 14/03/2013

Developing mental models using Terminology (1) cognitive models  Beacons ◦ Recognizable or familiar features in the code that act Mental Model Problem Domain as cues to the presence of certain structures  Swapping of two variables is a beacon for a sort routine  Plans Mappings ◦ Knowledge elements for developing and validating expectations, interpretations and inferences Cognitive Models ◦ Programming plans and domain plans ◦ Often referred to as clichés, schemas, idioms ◦ Low-level pattern Programming Software System ◦ Slot types (generalized templates) and slot fillers Domain (specific solutions)

13 14

Examples of programming plans, Slot types and fillers (plans) clichés, schemas, or slices  An example of a slot type could be a function such as a sort routine  A slot filler could be a particular implementation of a sort routine, for example quicksort  Slot fillers are related to slot types via either a Kind-of or an Is-a relationship.

 Reading input  Counting input  Running total  Computing average  Handling exceptions

Terminology (2) cxref command

 Rules of discourse  Analyzes C files and builds a cross-reference table ◦ Rules or conventions of programming  Uses a special version of cc to include #define'd  naming standards, indentation, white space, in-line documentation information in its symbol table. standards, exception handling style, use of include files  Generates a list of all symbols (auto, static, and global) ◦ Can be imposed by in each individual file.  Python  Includes four fields: NAME, FILE, FUNCTION, LINE ◦ Rules of discourse set up expectations in the ◦ The line numbers appearing in the LINE field also show mind of programmer reference marks as appropriate. The reference marks include:  Cross referencing  assignment =  declaration – ◦ Relates different abstraction levels such as a control flow  definition * and functional view by mapping program parts to  general reference functional descriptions

17 18

3 14/03/2013

Cognitive models of program What does this piece code do? comprehension  Bottom-up comprehension maxValue := table[0];  Top-down comprehension for k := 1 to MAXINDEX do  Knowledge based understanding model if table [k] > maxValue then  Systematic and as-needed strategies maxValue := table [k]  Integrated meta-model of program end comprehension end

 Experts do this much faster than novices, so bottom up comprehension is much more successful for experts than novices.

19

Bottom-up comprehension (1) Bottom-up comprehension (2)

 Starts understanding from the source code, This theory suggests that programmers understand constructing higher level abstractions using chunking programs by reading the source code and and concept assignment documentation, and mentally chunking this ◦ information into progressively larger chunks until an Shneiderman and Mayer 79 understanding of the entire program is achieved, uses ◦ Pennington 87 both syntactic and semantic knowledge ◦ Biggerstaff, et al. 93  Chunking creates new higher level abstractions from  Chunks are syntactic or semantic mental abstractions lower level structures of text structures within the source code  When higher level structures are recognized, they  Syntactic knowledge: language syntax, available replace more detailed lower level ones routines  This helps to overcome the limitations of the human  Semantic knowledge: general and task related memory when confronted with too many pieces of information Proposed by Shneiderman & Mayer

21 22

Bottom-up comprehension (3) Top-down comprehension (1)

Pennington also proposed a bottom up model and  Tries to reconstruct the mappings from the suggests that maintainers first develop a program model, and then a situation model: problem domain into the programming domain that were made when programming the system  Program model ◦ Brooks 83 ◦ Based on control flow abstractions ◦ Developed when code is completely new to programmers ◦ Soloway and Ehrlich 84 ◦ Developed bottom up via beacons – identification of code  Reconstruction is expectation-driven control primes in the program  Situation model ◦ Understanding starts with some pre-existing ◦ data flow and functional abstractions hypotheses about the functionality of the system and ◦ Also developed bottom-up – requires knowledge of real world the engineer investigates whether they hold, should domains (domain plans) be rejected, or refined in a hierarchical way ◦ Cross referencing is used to arrive at the overall program goal

23 24

4 14/03/2013

Top-down comprehension (2) Examples of beacons

 According to Brookes  Internal to the program: ◦ Prologue comments ◦ Programmer develops a hierarchy of hypotheses ◦ Variable, method, procedure, package names ◦ Make heavy use of beacons (cues) ◦ Data declarations ◦ Understanding is complete when a complete set of ◦ In-line comments mappings can be made from the problem domain to ◦ Subroutine or file structure the programming domain ◦ I/O formats ◦ XML schemas  External to the program ◦ User manuals ◦ Cross reference listings ◦ Documentation

25 26

Top-down comprehension (3) Opportunistic approach

According to Soloway & Ehrlich  There is no such thing as a pure top-down or  Three types of programming plans: pure bottom-up approach ◦ Strategic plans – describe a global strategy, domain independent  To create mental representations of ◦ Tactical plans – local strategies for solving a problem, language independent the software system programmers frequently ◦ Implementation plans – how to implement tactical plans, change between top-down language dependent – may contain code fragments and bottom-up approaches  Rules of programming discourse and beacons are used ◦ Letovsky 86 to decompose plans into lower level plans  Or even combine them  Delocalized plans are plans which are implemented in a ◦ Mayrhauser and Vans 95, 96, 97 distributed manner throughout the program and complicate program comprehension  Separation of concerns, aspects oriented programs

27 28

Knowledge-based understanding (1) Knowledge-based understanding (2)

 Letovsky 86  Knowledge base  Describes programmers as opportunistic  Mental model – 3 layers: processors capable of exploiting either bottom-up ◦ Specification—high level abstract view or top-down cues as they become available. ◦ Implementation  Three components to his model: ◦ Annotation • Knowledge base: encodes a programmer’s expertise and knowledge before the task  Assimilation process • Mental model: encodes the current understanding of the ◦ May occur bottom-up or top-down or some program combination of the two in an opportunistic manner • Assimilation process: describes how the mental model is ◦ Makes use of existing knowledge and any external formed using the programmers knowledge and source help such as source code and documentation code and other documentation ◦ Conjectures  His study involved  Why: hypothesize the purpose of a function or design choice ◦ Programmers with unfamiliar code  How: hypothesize the method for accomplishing a program goal ◦ Ask these programmers to do a task  What: hypothesize classification (e.g. variable or function) ◦ Asked them to use think-aloud

5 14/03/2013

Systematic/as-needed strategies Integrated meta-model

 Littman et al.  von Mayrhauser/Vans – components: ◦ ◦ Microstrategies top-down model (domain) ◦ program model (control flow) Comprehension  inquiry episodes and delocalized plans processes ◦ situation model (data flow) } ◦ Macrostrategies  systematic and as-needed ◦ knowledge base (programmer background)

 Experiments show that programmers switch between all three comprehension models

31 32

Static program analysis

 Def. The process of inferring results about the nature of a program according to some model without executing the subject program

 Syntactic analysis, type checking and inference  Control and data flow analysis  Structural analysis  Slicing and dicing  Cross references  Complexity measures  Navigation

33

6