SlideShare una empresa de Scribd logo
1 de 61
A Human-Centric Approach to Program Understanding
Ray Buse - PhD Proposal
University of Virginia, Department of Computer Science
DocumentationRuntime BehaviorReadability
1.20.2010
“The real question is not whether machines think,
but whether men do.“ -- B. F. Skinner
2
Requirements
Design
Implementation
Verification
Maintenance
3
Requirements
Design
Implementation
Verification
Maintenance
Maintenance accounts for about
70-90%
of the total lifecycle budget of a
software project.1,2
1. T. M. Pigoski. Practical Software Maintenance:
Best Practices for Managing Your Software
Investment. John Wiley & Sons, Inc., 1996.
2. R. C. Seacord, D. Plakosh, and G. A. Lewis.
Modernizing Legacy Systems: Software
Technologies, Engineering Process and Business
Practices. Addison-Wesley Longman Publishing
Co., Inc., Boston, MA, USA, 2003.
4
Requirements
Design
Implementation
Verification
Maintenance
Reading Code is the most
time consuming part of all
maintenance activities.3,4,5
3. L. E. Deimel Jr. The uses of program reading.
SIGCSE Bull., 17(2):5-14, 1985.
4. R. Glass. Facts and Fallacies of Software
Engineering. Addison-Wesley, 2003.
5. S. Rugaber. The use of domain knowledge in
program understanding. Ann. Softw. Eng.,(1-
4):143-192, 2000.
Reading Code
5
“Understanding code is by far the
activity at which professional
developers spend most of their time.” 6
Writing New
Code
Modifying
Existing Code
Understanding
Code
6. Peter Hallam. What Do Programmers
Really Do Anyway? Microsoft Developer
Network (MSDN) – C# Compiler. Jan 2006.
6
Reading Code is the most
Poorly Understood
Software Engineering activity.7,8
7. D. Parnas. Software aging. In Software Fundamentals. Addison-
Wesley, 2001.
8. D. Zokaities. Writing understandable code. In Software
Development, pages 48-49, jan 2002.
7
Reading Code is the most
Poorly Understood
Software Engineering activity.
4,387
780
16 1
ICSE PLDI
all program understanding
8
Understanding is difficult to…
Model
• Based on a complex combination of factors
Evaluate
• Lack of established metrics/baselines
• User studies are unattractive
9
Two Key Insights
• Machine Learning allows us to combine
many semantically shallow features of code
to gain new deep insights.
• PL Techniques can be adapted to generate
documentation artifacts that are directly
comparable to human created ones.
10
Thesis
We can combine insights from Machine
Learning and Programming Languages to
• Model aspects of code understanding
accurately and
• Generate output that compares favorably
with human documentation.
11
Proposal: Three Dimensions of Understanding
DocumentationRuntime BehaviorReadability
12
Proposal: Three Dimensions of Understanding
DocumentationRuntime BehaviorReadability
Textual characteristics
that make code
understandable.
Structural characteristics
that help developers
understand what a
program is expected to do.
Non-code text that
helps developers
understand a program.
13
Metrics for:
• Code Readability
• Path Execution Frequency
Algorithms for Documentation of:
• Exceptions
• Code Changes
• APIs
Research Projects
14
Broader Impact
New algorithms and metrics to support:
• Software Development and Composition
– Metrics for Software Quality Assurance
– Automatic Documentation
• Software Analysis
– Runtime Behavior model for optimizing
compilers
– Metrics for targeting analyses, prioritizing
output, and evaluating research
15
The rest of this proposal
• A review of each proposed contribution
– Technical Merit
– Evaluation Strategy
– Related Work
• Research timeline and other bookkeeping
• Concluding Remarks
16
Metrics for:
• Code Readability
• Path Execution Frequency
Algorithms for Documentation of:
• Exceptions
• Code Changes
• APIs Published
In Progress
ISSTA ‘08
ICSE ‘09
ISSTA ‘08 TSE ‘10
17
Metrics for:
• Code Readability
• Path Execution Frequency
Algorithms for Documentation of:
• Exceptions
• Code Changes
• APIs Published
In Progress
ISSTA ‘08
ICSE ‘09
ISSTA ‘08 TSE ‘10
18
/**
* Extend this Execution path by one level.
*
* @throws IllegalStateException If the move path invalid..
*/
private List<ExecutionPath> extend (ExecutionPath ep)
{
paths = new LinkedList<ExecutionPath>();
Unit last = ep.getLast();
List<Unit> succs = graph.getSuccsOf(last);
//this is the end of the path
if (succs.isEmpty())
{
ep.setComplete(true);
paths.add(ep);
return paths;
}
if (succs.size() == 1)
{
Unit s = succs.get(0);
if (ep.contains(s))
{
//do nothing
}
else
{
ep.addLast(s);
if (graph.getTails().contains(s))
{
ep.setComplete(true);
}
Readability
Model human judgments
about code readability
Create a readability
metric
Key: Use textual
features to approximate
human judgments
19
Hypothesis
With a simple set of textual features, we can derive
from a set of human judgments an accurate model of
readability for code.
Success depends on
• Gathering human judgments
• Choosing predictive textual features
20
Data Gathering
• We asked 120 students at UVa to rate the
readability of a set of snippets…
21
Data Set Vertical bands indicate
snippets were
agreement was high
22
Choosing predictive textual features
We choose local code features
• Line length
• Length of identifier names
• Comment density
• Blank lines
• Presence of numbers
• [and 20 others]
Modeled with a Bayesian Classifier
23
Model
Performance
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0 20 40 60 80 100 120
Spearmancorrelationbetween
annotatorscoresandaveragescores
Human Annotators (sorted)
average human
our metric
Model agrees with humans
as much as they agree with
each other on average
24
Related Work
• Readability metrics for natural languages
– Very popular, DOD standards etc
• In the software domain
– Complexity metrics (often used, but utility is
questionable)
25
Conclusions
• We can automatically judge readability
about as well as the average human can
• This notion of readability shows significant
correlation with:
• Code churn
• A bug finder
• Program maturity
26
Metrics for:
• Code Readability
• Path Execution Frequency
Algorithms for Documentation of:
• Exceptions
• Code Changes
• APIs Published
In Progress
ISSTA ‘08
ICSE ‘09
ISSTA ‘08 TSE ‘10
27
/**
* Extend this Execution path by one level.
*
* @throws IllegalStateException If the move path invalid..
*/
private List<ExecutionPath> extend (ExecutionPath ep)
{
paths = new LinkedList<ExecutionPath>();
Unit last = ep.getLast();
List<Unit> succs = graph.getSuccsOf(last);
//this is the end of the path
if (succs.isEmpty())
{
ep.setComplete(true);
paths.add(ep);
return paths;
}
if (succs.size() == 1)
{
Unit s = succs.get(0);
if (ep.contains(s))
{
//do nothing
}
else
{
ep.addLast(s);
if (graph.getTails().contains(s))
{
ep.setComplete(true);
}
Runtime Behavior
Model path execution
frequency statically
Key: Use path surface
features to uncover
developer expectations
28
Key Idea
• Developers often have expectations about
common and uncommon cases in programs
• The structure of code they write can
sometimes reveal these expectations
29
Intuition
public V put(K key , V value)
{
if ( value == null )
throw new Exception();
if ( count >= threshold )
rehash();
index = key.hashCode() % length;
table[index] = new Entry(key, value);
count++;
return value;
}
*simplified from java.util.HashTable jdk6.0
Exception
Invocation that changes
a lot of the object state
Some
computation
30
Hypothesis
We can accurately predict the runtime
frequency of program paths by analyzing
their static surface features
Goal:
• Know what programs are likely to do without
having to run them (produce a static profile)
31
Applications for Static Profiles
Indicative (dynamic) profiles are often unavailable
Profile information can improve many analyses
• Profile guided optimization
• Complexity/Runtime estimation
• Anomaly detection
• Significance of difference between program
versions
• Prioritizing output from other static analyses
32
Approach
• Model path with a set of features that may
correlate with runtime path frequency
• Learn from programs for which we have
indicative workloads, we used a Logistic
Regression
• Predict which paths are most or
least likely in other programs
33
Evaluation
Choose 5% of all paths
and get 50% of
runtime behavior
Ranking by our
metric
Baseline: random
ranking
34
Evaluation
Baseline: random
ranking
Choose 1 path per
method and get 94%
of runtime behavior
Ranking by our
metric
35
Related Work
• Static Branch Prediction [Ball & Larus ’92]
– For each branch, which direction is most likely
– In a direct comparison, our tool is better
36
Conclusion
• A formal model that statically predicts
relative dynamic path execution frequencies
• The promise of helping other program
analyses and transformations
37
Metrics for:
• Code Readability
• Path Execution Frequency
Algorithms for Documentation of:
• Exceptions
• Code Changes
• APIs Published
In Progress
ISSTA ‘08
ICSE ‘09
ISSTA ‘08 TSE ‘10
38
/**
* Extend this Execution path by one level.
*
* @throws IllegalStateException If the move path invalid..
*/
private List<ExecutionPath> extend (ExecutionPath ep)
{
paths = new LinkedList<ExecutionPath>();
Unit last = ep.getLast();
List<Unit> succs = graph.getSuccsOf(last);
//this is the end of the path
if (succs.isEmpty())
{
ep.setComplete(true);
paths.add(ep);
return paths;
}
if (succs.size() == 1)
{
Unit s = succs.get(0);
if (ep.contains(s))
{
//do nothing
}
else
{
ep.addLast(s);
if (graph.getTails().contains(s))
{
ep.setComplete(true);
}
Documentation
Exceptions
APIs
Generate for:
/**
* Extend this Execution path by one level.
*
* @throws IllegalStateException If the move path invalid..
*/
private List<ExecutionPath> extend (ExecutionPath ep)
{
paths = new LinkedList<ExecutionPath>();
Unit last = ep.getLast();
List<Unit> succs = graph.getSuccsOf(last);
//this is the end of the path
if (succs.isEmpty())
{
ep.setComplete(true);
paths.add(ep);
return paths;
}
if (succs.size() == 1)
{
Unit s = succs.get(0);
if (ep.contains(s))
{
//do nothing
}
else
{
ep.addLast(s);
if (graph.getTails().contains(s))
{
ep.setComplete(true);
}
Version Changes
Key: Use symbolic
execution and
summarization
heuristics to generate
human-readable
results.
/**
* Extend this Execution path by one level.
*
* @throws IllegalStateException If the move path invalid..
*/
private List<ExecutionPath> extend (ExecutionPath ep)
{
paths = new LinkedList<ExecutionPath>();
Unit last = ep.getLast();
List<Unit> succs = graph.getSuccsOf(last);
//this is the end of the path
if (succs.isEmpty())
{
ep.setComplete(true);
paths.add(ep);
return paths;
}
if (succs.size() == 1)
{
Unit s = succs.get(0);
if (ep.contains(s))
{
//do nothing
}
else
{
ep.addLast(s);
if (graph.getTails().contains(s))
{
ep.setComplete(true);
}
39
Use
• For Internal Developers
– Easier to keep track of what’s going on
• For Maintenance and Testing
– Easier to read old code.
• For External Developers
– Easier to integrate off-the-shelf software libraries
40
Three Types of Documentation
• Exceptions
• Code Changes
• APIs
41
Documenting Exceptions
/**
* @throws Exception If the value is null
*/
public V put(K key , V value)
{
if ( value == null )
throw new Exception();
if ( count >= threshold )
rehash();
index = key.hashCode() % length;
...
*simplified from java.util.HashTable jdk6.0
Best practice dictates
that exceptions should
be documented
42
Documenting Exceptions
/**
* @throws Exception If the value is null
*/
public V put(K key , V value)
{
if ( value == null )
throw new Exception();
if ( count >= threshold )
rehash();
index = key.hashCode() % length;
...
*simplified from java.util.HashTable jdk6.0
Best practice dictates
that exceptions should
be documented
Does this method
throw an exception?
43
Importance
Mishandling or Not handling can lead to:
• Security vulnerabilities
• May disclose sensitive implementation
details
• Breaches of API encapsulation
• Any number of minor to serious system
failures
44
Hypothesis
Mechanical documentation of exceptions can
be at least as good as human on average.
• More complete
• More accurate
We extract paths to throw statements and
use symbolic execution to generate path
predicates
45
Examples
• Sometimes we do better:
• Sometimes we do about the same:
• Sometimes we do worse:
46
Key Results Our documentation is
as good as human over
80% of the time
47
Code Change Examples
jfreechart rev 3405
(start): Changed from Date to long,
(end): Likewise,
(getStartMillis): New method,
(getEndMillis): Likewise,
(getStart): Returns new date instance,
(getEnd): Likewise.
Jabref rev 2917
Fixed NullPointerException when
downloading external file and file directory
is undefined.
Phex 3542
Minor change
48
Subject: An appeal for more
descriptive commit messages
I know there is a lot going on but
please can we be a bit more
descriptive when commiting
changes. Recent log messages
have included:
"some cleanup"
"more external service work"
"Fixed a bug in wiring"
which are a lot less informative
than others...
http://osdir.com/ml/apache.webservices
.tuscany.devel/2006-02/msg00227.html
Toby,
Going forward, could you I ask you to be more
descriptive in your commit messages? Ideally you
should state what you've changed and also why
(unless it's obvious)... I know you're busy and this
takes more time, but it will help anyone who looks
through the log ...
http://lists.macosforge.org/pipermail/macports-dev/2009-
June/008881.html
Sorry to be a pain in the neck about this, but could
we please use more descriptive commit
messages? I do try to read the commit emails, but
since the vast majority of comments are "CAY-
XYZ", I can't really tell what's going on unless I
then look it up.
http://osdir.com/ml/java.cayenne.devel/2006-
10/msg00044.html
49
Key Idea
• Generate Documentation that describes the
effect of a change on the runtime behavior
of a program
– What conditions are necessary to activate the
change
– What the new behavior is
50
Algorithm
• Generate predicates for each statement
• Compare predicates across versions
• Summarize change and distill structured
output
When X,
Do Y
Instead of Z
51
Evaluation
Our documentation is
as good as human over
80% of the time
52
API Usage Documentation
“The greatest obstacle to learning
an API … is insufficient or
inadequate examples” 9
9. M. P. Robillard. What Makes APIs Hard to Learn? Answers
from Developers. IEEE Softw., 26(6):27-34, 2009.
53
API Usage Documentation
java.util.ObjectOutputStream
FileOutputStream fos = new
FileOutputStream("t.tmp");
ObjectOutputStream oos = new
ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Date());
oos.close();
weka.core.Instance
// Create the instance
Instance iExample = new Instance(4);
iExample.setValue((Attribute)fvWekaAttributes.elementAt(0), 1.0);
iExample.setValue((Attribute)fvWekaAttributes.elementAt(1), 0.5);
iExample.setValue((Attribute)fvWekaAttributes.elementAt(2), "gray");
iExample.setValue((Attribute)fvWekaAttributes.elementAt(3), "positive");
isTrainingSet.add(iExample);
java.util.BufferedReader
BufferedReader in = new
BufferedReader(new FileReader("foo.in"));
54
Key Idea
• Combine insights from specification mining,
automatic documentation, and code
summarization
• Specification mining false positives – usage
patterns that are common but aren't
required – are exactly what we want to find.
55
Algorithm
Given a target class to document, and a set of
code files that use the class (e.g., mined from
the web).
– Model usages of the classes as a finite state
machine or regular expression
– Combine machines that are similar
– Output most common machines as usage
examples
56
Evaluation
Manual comparison to JavaDoc examples
• Are we able to come up with the same
examples?
– Precision / Recall / F-measure
• User Study
57
Conclusion
To create algorithms for three types of
documentation:
– Exceptions
– Code Changes
– API Usage
Evaluate by comparing to human generated
documentation and/or with a user study
58
Research Timeline
59
A 2005 NASA survey found that the most
significant barrier to code reuse is that
software is “too difficult to understand” or is
“poorly documented.” 10
10. Nasa Software Reuse Working Group. Software reuse survey.
http://www.esdswg.com/softwarereuse/Resources/library/worki
ng_ group_ documents/survey2005, 2005.
60
Conclusion: Understanding programs at many levels
• How easy is it to understand and
maintain this software? Readability
• Where are the corner cases, and where
are the common paths? Runtime Behavior
• How can this code go wrong?
Documenting Exceptions
• How do I use this code? Documenting APIs
• What does proposed fix really do?
Documenting Changes
All Questions Encouraged
A Human-Centric Approach to Program Understanding
DocumentationRuntime BehaviorReadability
These slides, the proposal document, and much
more information is available at:
http://arrestedcomputing.com/proposal
Thanks for Coming!

Más contenido relacionado

La actualidad más candente

Software Analytics: Data Analytics for Software Engineering
Software Analytics: Data Analytics for Software EngineeringSoftware Analytics: Data Analytics for Software Engineering
Software Analytics: Data Analytics for Software EngineeringTao Xie
 
Publish or Perish: Questioning the Impact of Our Research on the Software Dev...
Publish or Perish: Questioning the Impact of Our Research on the Software Dev...Publish or Perish: Questioning the Impact of Our Research on the Software Dev...
Publish or Perish: Questioning the Impact of Our Research on the Software Dev...Margaret-Anne Storey
 
Requirements Analysis and Management using Innoslate
Requirements Analysis and Management using InnoslateRequirements Analysis and Management using Innoslate
Requirements Analysis and Management using InnoslateElizabeth Steiner
 
IS3242 Case Presentation
IS3242 Case PresentationIS3242 Case Presentation
IS3242 Case PresentationJ M
 
Understanding software metrics
Understanding software metricsUnderstanding software metrics
Understanding software metricsTushar Sharma
 
Reducing Technical Debt: Using Persuasive Technology for Encouraging Software...
Reducing Technical Debt: Using Persuasive Technology for Encouraging Software...Reducing Technical Debt: Using Persuasive Technology for Encouraging Software...
Reducing Technical Debt: Using Persuasive Technology for Encouraging Software...Hayim Makabee
 
First steps in testing analytics: Does test code quality matter?
First steps in testing analytics: Does test code quality matter?First steps in testing analytics: Does test code quality matter?
First steps in testing analytics: Does test code quality matter?Andy Zaidman
 
Reducing Technical Debt
Reducing Technical DebtReducing Technical Debt
Reducing Technical DebtHayim Makabee
 
Application Security Testing for Software Engineers: An approach to build sof...
Application Security Testing for Software Engineers: An approach to build sof...Application Security Testing for Software Engineers: An approach to build sof...
Application Security Testing for Software Engineers: An approach to build sof...Michael Hidalgo
 
Adaptation of the technology of the static code analyzer for developing paral...
Adaptation of the technology of the static code analyzer for developing paral...Adaptation of the technology of the static code analyzer for developing paral...
Adaptation of the technology of the static code analyzer for developing paral...PVS-Studio
 
Adopting code reviews for agile software development
Adopting code reviews for agile software developmentAdopting code reviews for agile software development
Adopting code reviews for agile software developmentmariobernhart
 
Regular Expression Denial of Service RegexDoS
Regular Expression Denial of  Service RegexDoSRegular Expression Denial of  Service RegexDoS
Regular Expression Denial of Service RegexDoSMichael Hidalgo
 
Mining Testing Questions on Stack Overflow
Mining Testing Questions on Stack OverflowMining Testing Questions on Stack Overflow
Mining Testing Questions on Stack OverflowPavneet Singh Kochhar
 
Measuring Agile Software Development
Measuring Agile Software DevelopmentMeasuring Agile Software Development
Measuring Agile Software DevelopmentMiroslaw Staron
 
Aligning Bounded Contexts with Subdomains in Legacy Code - NDC Oslo 2021
Aligning Bounded Contexts with Subdomains in Legacy Code - NDC Oslo 2021Aligning Bounded Contexts with Subdomains in Legacy Code - NDC Oslo 2021
Aligning Bounded Contexts with Subdomains in Legacy Code - NDC Oslo 2021Mufrid Krilic
 
Cross-project defect prediction
Cross-project defect predictionCross-project defect prediction
Cross-project defect predictionThomas Zimmermann
 

La actualidad más candente (20)

Software Analytics: Data Analytics for Software Engineering
Software Analytics: Data Analytics for Software EngineeringSoftware Analytics: Data Analytics for Software Engineering
Software Analytics: Data Analytics for Software Engineering
 
Publish or Perish: Questioning the Impact of Our Research on the Software Dev...
Publish or Perish: Questioning the Impact of Our Research on the Software Dev...Publish or Perish: Questioning the Impact of Our Research on the Software Dev...
Publish or Perish: Questioning the Impact of Our Research on the Software Dev...
 
Exclusive Cover Focus
Exclusive Cover FocusExclusive Cover Focus
Exclusive Cover Focus
 
Requirements Analysis and Management using Innoslate
Requirements Analysis and Management using InnoslateRequirements Analysis and Management using Innoslate
Requirements Analysis and Management using Innoslate
 
IS3242 Case Presentation
IS3242 Case PresentationIS3242 Case Presentation
IS3242 Case Presentation
 
Understanding software metrics
Understanding software metricsUnderstanding software metrics
Understanding software metrics
 
Reducing Technical Debt: Using Persuasive Technology for Encouraging Software...
Reducing Technical Debt: Using Persuasive Technology for Encouraging Software...Reducing Technical Debt: Using Persuasive Technology for Encouraging Software...
Reducing Technical Debt: Using Persuasive Technology for Encouraging Software...
 
First steps in testing analytics: Does test code quality matter?
First steps in testing analytics: Does test code quality matter?First steps in testing analytics: Does test code quality matter?
First steps in testing analytics: Does test code quality matter?
 
Reducing Technical Debt
Reducing Technical DebtReducing Technical Debt
Reducing Technical Debt
 
Cser13.ppt
Cser13.pptCser13.ppt
Cser13.ppt
 
Application Security Testing for Software Engineers: An approach to build sof...
Application Security Testing for Software Engineers: An approach to build sof...Application Security Testing for Software Engineers: An approach to build sof...
Application Security Testing for Software Engineers: An approach to build sof...
 
Adaptation of the technology of the static code analyzer for developing paral...
Adaptation of the technology of the static code analyzer for developing paral...Adaptation of the technology of the static code analyzer for developing paral...
Adaptation of the technology of the static code analyzer for developing paral...
 
Adopting code reviews for agile software development
Adopting code reviews for agile software developmentAdopting code reviews for agile software development
Adopting code reviews for agile software development
 
Regular Expression Denial of Service RegexDoS
Regular Expression Denial of  Service RegexDoSRegular Expression Denial of  Service RegexDoS
Regular Expression Denial of Service RegexDoS
 
Mining Testing Questions on Stack Overflow
Mining Testing Questions on Stack OverflowMining Testing Questions on Stack Overflow
Mining Testing Questions on Stack Overflow
 
Measuring Agile Software Development
Measuring Agile Software DevelopmentMeasuring Agile Software Development
Measuring Agile Software Development
 
Aligning Bounded Contexts with Subdomains in Legacy Code - NDC Oslo 2021
Aligning Bounded Contexts with Subdomains in Legacy Code - NDC Oslo 2021Aligning Bounded Contexts with Subdomains in Legacy Code - NDC Oslo 2021
Aligning Bounded Contexts with Subdomains in Legacy Code - NDC Oslo 2021
 
Enase20.ppt
Enase20.pptEnase20.ppt
Enase20.ppt
 
Cross-project defect prediction
Cross-project defect predictionCross-project defect prediction
Cross-project defect prediction
 
My life as a cyborg
My life as a cyborg My life as a cyborg
My life as a cyborg
 

Similar a Human-Centric Approach to Program Understanding

SE UNIT 1 NOTES OF SE SOFTWARE ENGG AND SE
SE UNIT 1 NOTES OF SE SOFTWARE ENGG AND SESE UNIT 1 NOTES OF SE SOFTWARE ENGG AND SE
SE UNIT 1 NOTES OF SE SOFTWARE ENGG AND SEAbhishekTripathi709328
 
Software engineering practices and software quality empirical research results
Software engineering practices and software quality empirical research resultsSoftware engineering practices and software quality empirical research results
Software engineering practices and software quality empirical research resultsNikolai Avteniev
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Software Engineering.ppt
Software Engineering.pptSoftware Engineering.ppt
Software Engineering.pptHODCOMPUTER10
 
boughtonalexand jdjdjfjjfjfjfjnfjfjjjfkdifij
boughtonalexand jdjdjfjjfjfjfjnfjfjjjfkdifijboughtonalexand jdjdjfjjfjfjfjnfjfjjjfkdifij
boughtonalexand jdjdjfjjfjfjfjnfjfjjjfkdifijakd3143
 
Line Of Code(LOC) In Software Engineering By NADEEM AHMED FROM DEPALPUR
Line Of Code(LOC) In Software Engineering By NADEEM AHMED FROM DEPALPURLine Of Code(LOC) In Software Engineering By NADEEM AHMED FROM DEPALPUR
Line Of Code(LOC) In Software Engineering By NADEEM AHMED FROM DEPALPURNA000000
 
Traceability Beyond Source Code: An Elusive Target?
Traceability Beyond Source Code: An Elusive Target?Traceability Beyond Source Code: An Elusive Target?
Traceability Beyond Source Code: An Elusive Target?Lionel Briand
 
Elementary Probability theory Chapter 2.pptx
Elementary Probability theory Chapter 2.pptxElementary Probability theory Chapter 2.pptx
Elementary Probability theory Chapter 2.pptxethiouniverse
 
Process and Project Metrics-1
Process and Project Metrics-1Process and Project Metrics-1
Process and Project Metrics-1Saqib Raza
 

Similar a Human-Centric Approach to Program Understanding (20)

lecture 1.pdf
lecture 1.pdflecture 1.pdf
lecture 1.pdf
 
SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
 
ch1_introduction (1).ppt
ch1_introduction (1).pptch1_introduction (1).ppt
ch1_introduction (1).ppt
 
ch1_introduction (2).ppt
ch1_introduction (2).pptch1_introduction (2).ppt
ch1_introduction (2).ppt
 
ch1_introduction.ppt
ch1_introduction.pptch1_introduction.ppt
ch1_introduction.ppt
 
SE UNIT 1 NOTES OF SE SOFTWARE ENGG AND SE
SE UNIT 1 NOTES OF SE SOFTWARE ENGG AND SESE UNIT 1 NOTES OF SE SOFTWARE ENGG AND SE
SE UNIT 1 NOTES OF SE SOFTWARE ENGG AND SE
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Software engineering practices and software quality empirical research results
Software engineering practices and software quality empirical research resultsSoftware engineering practices and software quality empirical research results
Software engineering practices and software quality empirical research results
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Software Engineering.ppt
Software Engineering.pptSoftware Engineering.ppt
Software Engineering.ppt
 
boughtonalexand jdjdjfjjfjfjfjnfjfjjjfkdifij
boughtonalexand jdjdjfjjfjfjfjnfjfjjjfkdifijboughtonalexand jdjdjfjjfjfjfjnfjfjjjfkdifij
boughtonalexand jdjdjfjjfjfjfjnfjfjjjfkdifij
 
Line Of Code(LOC) In Software Engineering By NADEEM AHMED FROM DEPALPUR
Line Of Code(LOC) In Software Engineering By NADEEM AHMED FROM DEPALPURLine Of Code(LOC) In Software Engineering By NADEEM AHMED FROM DEPALPUR
Line Of Code(LOC) In Software Engineering By NADEEM AHMED FROM DEPALPUR
 
Code Inspection
Code InspectionCode Inspection
Code Inspection
 
Traceability Beyond Source Code: An Elusive Target?
Traceability Beyond Source Code: An Elusive Target?Traceability Beyond Source Code: An Elusive Target?
Traceability Beyond Source Code: An Elusive Target?
 
software engineering
 software engineering software engineering
software engineering
 
Software Engineering and Introduction, Activities and ProcessModels
Software Engineering and Introduction, Activities and ProcessModels Software Engineering and Introduction, Activities and ProcessModels
Software Engineering and Introduction, Activities and ProcessModels
 
Elementary Probability theory Chapter 2.pptx
Elementary Probability theory Chapter 2.pptxElementary Probability theory Chapter 2.pptx
Elementary Probability theory Chapter 2.pptx
 
Process and Project Metrics-1
Process and Project Metrics-1Process and Project Metrics-1
Process and Project Metrics-1
 
Scope of software engineering
Scope of software engineeringScope of software engineering
Scope of software engineering
 
SE Unit 1
SE Unit 1SE Unit 1
SE Unit 1
 

Human-Centric Approach to Program Understanding

  • 1. A Human-Centric Approach to Program Understanding Ray Buse - PhD Proposal University of Virginia, Department of Computer Science DocumentationRuntime BehaviorReadability 1.20.2010 “The real question is not whether machines think, but whether men do.“ -- B. F. Skinner
  • 3. 3 Requirements Design Implementation Verification Maintenance Maintenance accounts for about 70-90% of the total lifecycle budget of a software project.1,2 1. T. M. Pigoski. Practical Software Maintenance: Best Practices for Managing Your Software Investment. John Wiley & Sons, Inc., 1996. 2. R. C. Seacord, D. Plakosh, and G. A. Lewis. Modernizing Legacy Systems: Software Technologies, Engineering Process and Business Practices. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 2003.
  • 4. 4 Requirements Design Implementation Verification Maintenance Reading Code is the most time consuming part of all maintenance activities.3,4,5 3. L. E. Deimel Jr. The uses of program reading. SIGCSE Bull., 17(2):5-14, 1985. 4. R. Glass. Facts and Fallacies of Software Engineering. Addison-Wesley, 2003. 5. S. Rugaber. The use of domain knowledge in program understanding. Ann. Softw. Eng.,(1- 4):143-192, 2000. Reading Code
  • 5. 5 “Understanding code is by far the activity at which professional developers spend most of their time.” 6 Writing New Code Modifying Existing Code Understanding Code 6. Peter Hallam. What Do Programmers Really Do Anyway? Microsoft Developer Network (MSDN) – C# Compiler. Jan 2006.
  • 6. 6 Reading Code is the most Poorly Understood Software Engineering activity.7,8 7. D. Parnas. Software aging. In Software Fundamentals. Addison- Wesley, 2001. 8. D. Zokaities. Writing understandable code. In Software Development, pages 48-49, jan 2002.
  • 7. 7 Reading Code is the most Poorly Understood Software Engineering activity. 4,387 780 16 1 ICSE PLDI all program understanding
  • 8. 8 Understanding is difficult to… Model • Based on a complex combination of factors Evaluate • Lack of established metrics/baselines • User studies are unattractive
  • 9. 9 Two Key Insights • Machine Learning allows us to combine many semantically shallow features of code to gain new deep insights. • PL Techniques can be adapted to generate documentation artifacts that are directly comparable to human created ones.
  • 10. 10 Thesis We can combine insights from Machine Learning and Programming Languages to • Model aspects of code understanding accurately and • Generate output that compares favorably with human documentation.
  • 11. 11 Proposal: Three Dimensions of Understanding DocumentationRuntime BehaviorReadability
  • 12. 12 Proposal: Three Dimensions of Understanding DocumentationRuntime BehaviorReadability Textual characteristics that make code understandable. Structural characteristics that help developers understand what a program is expected to do. Non-code text that helps developers understand a program.
  • 13. 13 Metrics for: • Code Readability • Path Execution Frequency Algorithms for Documentation of: • Exceptions • Code Changes • APIs Research Projects
  • 14. 14 Broader Impact New algorithms and metrics to support: • Software Development and Composition – Metrics for Software Quality Assurance – Automatic Documentation • Software Analysis – Runtime Behavior model for optimizing compilers – Metrics for targeting analyses, prioritizing output, and evaluating research
  • 15. 15 The rest of this proposal • A review of each proposed contribution – Technical Merit – Evaluation Strategy – Related Work • Research timeline and other bookkeeping • Concluding Remarks
  • 16. 16 Metrics for: • Code Readability • Path Execution Frequency Algorithms for Documentation of: • Exceptions • Code Changes • APIs Published In Progress ISSTA ‘08 ICSE ‘09 ISSTA ‘08 TSE ‘10
  • 17. 17 Metrics for: • Code Readability • Path Execution Frequency Algorithms for Documentation of: • Exceptions • Code Changes • APIs Published In Progress ISSTA ‘08 ICSE ‘09 ISSTA ‘08 TSE ‘10
  • 18. 18 /** * Extend this Execution path by one level. * * @throws IllegalStateException If the move path invalid.. */ private List<ExecutionPath> extend (ExecutionPath ep) { paths = new LinkedList<ExecutionPath>(); Unit last = ep.getLast(); List<Unit> succs = graph.getSuccsOf(last); //this is the end of the path if (succs.isEmpty()) { ep.setComplete(true); paths.add(ep); return paths; } if (succs.size() == 1) { Unit s = succs.get(0); if (ep.contains(s)) { //do nothing } else { ep.addLast(s); if (graph.getTails().contains(s)) { ep.setComplete(true); } Readability Model human judgments about code readability Create a readability metric Key: Use textual features to approximate human judgments
  • 19. 19 Hypothesis With a simple set of textual features, we can derive from a set of human judgments an accurate model of readability for code. Success depends on • Gathering human judgments • Choosing predictive textual features
  • 20. 20 Data Gathering • We asked 120 students at UVa to rate the readability of a set of snippets…
  • 21. 21 Data Set Vertical bands indicate snippets were agreement was high
  • 22. 22 Choosing predictive textual features We choose local code features • Line length • Length of identifier names • Comment density • Blank lines • Presence of numbers • [and 20 others] Modeled with a Bayesian Classifier
  • 23. 23 Model Performance 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0 20 40 60 80 100 120 Spearmancorrelationbetween annotatorscoresandaveragescores Human Annotators (sorted) average human our metric Model agrees with humans as much as they agree with each other on average
  • 24. 24 Related Work • Readability metrics for natural languages – Very popular, DOD standards etc • In the software domain – Complexity metrics (often used, but utility is questionable)
  • 25. 25 Conclusions • We can automatically judge readability about as well as the average human can • This notion of readability shows significant correlation with: • Code churn • A bug finder • Program maturity
  • 26. 26 Metrics for: • Code Readability • Path Execution Frequency Algorithms for Documentation of: • Exceptions • Code Changes • APIs Published In Progress ISSTA ‘08 ICSE ‘09 ISSTA ‘08 TSE ‘10
  • 27. 27 /** * Extend this Execution path by one level. * * @throws IllegalStateException If the move path invalid.. */ private List<ExecutionPath> extend (ExecutionPath ep) { paths = new LinkedList<ExecutionPath>(); Unit last = ep.getLast(); List<Unit> succs = graph.getSuccsOf(last); //this is the end of the path if (succs.isEmpty()) { ep.setComplete(true); paths.add(ep); return paths; } if (succs.size() == 1) { Unit s = succs.get(0); if (ep.contains(s)) { //do nothing } else { ep.addLast(s); if (graph.getTails().contains(s)) { ep.setComplete(true); } Runtime Behavior Model path execution frequency statically Key: Use path surface features to uncover developer expectations
  • 28. 28 Key Idea • Developers often have expectations about common and uncommon cases in programs • The structure of code they write can sometimes reveal these expectations
  • 29. 29 Intuition public V put(K key , V value) { if ( value == null ) throw new Exception(); if ( count >= threshold ) rehash(); index = key.hashCode() % length; table[index] = new Entry(key, value); count++; return value; } *simplified from java.util.HashTable jdk6.0 Exception Invocation that changes a lot of the object state Some computation
  • 30. 30 Hypothesis We can accurately predict the runtime frequency of program paths by analyzing their static surface features Goal: • Know what programs are likely to do without having to run them (produce a static profile)
  • 31. 31 Applications for Static Profiles Indicative (dynamic) profiles are often unavailable Profile information can improve many analyses • Profile guided optimization • Complexity/Runtime estimation • Anomaly detection • Significance of difference between program versions • Prioritizing output from other static analyses
  • 32. 32 Approach • Model path with a set of features that may correlate with runtime path frequency • Learn from programs for which we have indicative workloads, we used a Logistic Regression • Predict which paths are most or least likely in other programs
  • 33. 33 Evaluation Choose 5% of all paths and get 50% of runtime behavior Ranking by our metric Baseline: random ranking
  • 34. 34 Evaluation Baseline: random ranking Choose 1 path per method and get 94% of runtime behavior Ranking by our metric
  • 35. 35 Related Work • Static Branch Prediction [Ball & Larus ’92] – For each branch, which direction is most likely – In a direct comparison, our tool is better
  • 36. 36 Conclusion • A formal model that statically predicts relative dynamic path execution frequencies • The promise of helping other program analyses and transformations
  • 37. 37 Metrics for: • Code Readability • Path Execution Frequency Algorithms for Documentation of: • Exceptions • Code Changes • APIs Published In Progress ISSTA ‘08 ICSE ‘09 ISSTA ‘08 TSE ‘10
  • 38. 38 /** * Extend this Execution path by one level. * * @throws IllegalStateException If the move path invalid.. */ private List<ExecutionPath> extend (ExecutionPath ep) { paths = new LinkedList<ExecutionPath>(); Unit last = ep.getLast(); List<Unit> succs = graph.getSuccsOf(last); //this is the end of the path if (succs.isEmpty()) { ep.setComplete(true); paths.add(ep); return paths; } if (succs.size() == 1) { Unit s = succs.get(0); if (ep.contains(s)) { //do nothing } else { ep.addLast(s); if (graph.getTails().contains(s)) { ep.setComplete(true); } Documentation Exceptions APIs Generate for: /** * Extend this Execution path by one level. * * @throws IllegalStateException If the move path invalid.. */ private List<ExecutionPath> extend (ExecutionPath ep) { paths = new LinkedList<ExecutionPath>(); Unit last = ep.getLast(); List<Unit> succs = graph.getSuccsOf(last); //this is the end of the path if (succs.isEmpty()) { ep.setComplete(true); paths.add(ep); return paths; } if (succs.size() == 1) { Unit s = succs.get(0); if (ep.contains(s)) { //do nothing } else { ep.addLast(s); if (graph.getTails().contains(s)) { ep.setComplete(true); } Version Changes Key: Use symbolic execution and summarization heuristics to generate human-readable results. /** * Extend this Execution path by one level. * * @throws IllegalStateException If the move path invalid.. */ private List<ExecutionPath> extend (ExecutionPath ep) { paths = new LinkedList<ExecutionPath>(); Unit last = ep.getLast(); List<Unit> succs = graph.getSuccsOf(last); //this is the end of the path if (succs.isEmpty()) { ep.setComplete(true); paths.add(ep); return paths; } if (succs.size() == 1) { Unit s = succs.get(0); if (ep.contains(s)) { //do nothing } else { ep.addLast(s); if (graph.getTails().contains(s)) { ep.setComplete(true); }
  • 39. 39 Use • For Internal Developers – Easier to keep track of what’s going on • For Maintenance and Testing – Easier to read old code. • For External Developers – Easier to integrate off-the-shelf software libraries
  • 40. 40 Three Types of Documentation • Exceptions • Code Changes • APIs
  • 41. 41 Documenting Exceptions /** * @throws Exception If the value is null */ public V put(K key , V value) { if ( value == null ) throw new Exception(); if ( count >= threshold ) rehash(); index = key.hashCode() % length; ... *simplified from java.util.HashTable jdk6.0 Best practice dictates that exceptions should be documented
  • 42. 42 Documenting Exceptions /** * @throws Exception If the value is null */ public V put(K key , V value) { if ( value == null ) throw new Exception(); if ( count >= threshold ) rehash(); index = key.hashCode() % length; ... *simplified from java.util.HashTable jdk6.0 Best practice dictates that exceptions should be documented Does this method throw an exception?
  • 43. 43 Importance Mishandling or Not handling can lead to: • Security vulnerabilities • May disclose sensitive implementation details • Breaches of API encapsulation • Any number of minor to serious system failures
  • 44. 44 Hypothesis Mechanical documentation of exceptions can be at least as good as human on average. • More complete • More accurate We extract paths to throw statements and use symbolic execution to generate path predicates
  • 45. 45 Examples • Sometimes we do better: • Sometimes we do about the same: • Sometimes we do worse:
  • 46. 46 Key Results Our documentation is as good as human over 80% of the time
  • 47. 47 Code Change Examples jfreechart rev 3405 (start): Changed from Date to long, (end): Likewise, (getStartMillis): New method, (getEndMillis): Likewise, (getStart): Returns new date instance, (getEnd): Likewise. Jabref rev 2917 Fixed NullPointerException when downloading external file and file directory is undefined. Phex 3542 Minor change
  • 48. 48 Subject: An appeal for more descriptive commit messages I know there is a lot going on but please can we be a bit more descriptive when commiting changes. Recent log messages have included: "some cleanup" "more external service work" "Fixed a bug in wiring" which are a lot less informative than others... http://osdir.com/ml/apache.webservices .tuscany.devel/2006-02/msg00227.html Toby, Going forward, could you I ask you to be more descriptive in your commit messages? Ideally you should state what you've changed and also why (unless it's obvious)... I know you're busy and this takes more time, but it will help anyone who looks through the log ... http://lists.macosforge.org/pipermail/macports-dev/2009- June/008881.html Sorry to be a pain in the neck about this, but could we please use more descriptive commit messages? I do try to read the commit emails, but since the vast majority of comments are "CAY- XYZ", I can't really tell what's going on unless I then look it up. http://osdir.com/ml/java.cayenne.devel/2006- 10/msg00044.html
  • 49. 49 Key Idea • Generate Documentation that describes the effect of a change on the runtime behavior of a program – What conditions are necessary to activate the change – What the new behavior is
  • 50. 50 Algorithm • Generate predicates for each statement • Compare predicates across versions • Summarize change and distill structured output When X, Do Y Instead of Z
  • 51. 51 Evaluation Our documentation is as good as human over 80% of the time
  • 52. 52 API Usage Documentation “The greatest obstacle to learning an API … is insufficient or inadequate examples” 9 9. M. P. Robillard. What Makes APIs Hard to Learn? Answers from Developers. IEEE Softw., 26(6):27-34, 2009.
  • 53. 53 API Usage Documentation java.util.ObjectOutputStream FileOutputStream fos = new FileOutputStream("t.tmp"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeInt(12345); oos.writeObject("Today"); oos.writeObject(new Date()); oos.close(); weka.core.Instance // Create the instance Instance iExample = new Instance(4); iExample.setValue((Attribute)fvWekaAttributes.elementAt(0), 1.0); iExample.setValue((Attribute)fvWekaAttributes.elementAt(1), 0.5); iExample.setValue((Attribute)fvWekaAttributes.elementAt(2), "gray"); iExample.setValue((Attribute)fvWekaAttributes.elementAt(3), "positive"); isTrainingSet.add(iExample); java.util.BufferedReader BufferedReader in = new BufferedReader(new FileReader("foo.in"));
  • 54. 54 Key Idea • Combine insights from specification mining, automatic documentation, and code summarization • Specification mining false positives – usage patterns that are common but aren't required – are exactly what we want to find.
  • 55. 55 Algorithm Given a target class to document, and a set of code files that use the class (e.g., mined from the web). – Model usages of the classes as a finite state machine or regular expression – Combine machines that are similar – Output most common machines as usage examples
  • 56. 56 Evaluation Manual comparison to JavaDoc examples • Are we able to come up with the same examples? – Precision / Recall / F-measure • User Study
  • 57. 57 Conclusion To create algorithms for three types of documentation: – Exceptions – Code Changes – API Usage Evaluate by comparing to human generated documentation and/or with a user study
  • 59. 59 A 2005 NASA survey found that the most significant barrier to code reuse is that software is “too difficult to understand” or is “poorly documented.” 10 10. Nasa Software Reuse Working Group. Software reuse survey. http://www.esdswg.com/softwarereuse/Resources/library/worki ng_ group_ documents/survey2005, 2005.
  • 60. 60 Conclusion: Understanding programs at many levels • How easy is it to understand and maintain this software? Readability • Where are the corner cases, and where are the common paths? Runtime Behavior • How can this code go wrong? Documenting Exceptions • How do I use this code? Documenting APIs • What does proposed fix really do? Documenting Changes
  • 61. All Questions Encouraged A Human-Centric Approach to Program Understanding DocumentationRuntime BehaviorReadability These slides, the proposal document, and much more information is available at: http://arrestedcomputing.com/proposal Thanks for Coming!