You are on page 1of 70

What would other

programmers do?
Suggesting solutions to error messages
Björn Hartmann
University of California, Berkeley
EECS, Computer Science Division
bjoern@eecs.berkeley.edu

Daniel MacDougall, Joel Brandt,


Scott R. Klemmer
Stanford University HCI Group
End-user programmers outnumber
professional software developers.
To write code, end users often find and
modify existing examples.

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 2
End-user programmers outnumber
professional software developers.
To write code, end users often find and
modify existing examples.
This strategy does not work well for
debugging. (but it should)

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 3
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 4
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 5
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 6
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 7
Research Idea:
Help programmers fix errors by showing
examples how other programmers have
fixed similar errors in the past.
(In real-time, automatically)

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 8
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 9
Test Environment: Processing

images: processing.org

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 10
photo: d. shiffman

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 11
MIT Media Lab, Sensable Cities

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 12
Scenario

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 13
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 14
Architecture

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 15
Three Steps
Collecting example fixes
Finding relevant fixes
Presenting found fixes

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 16
Three Steps
Collecting example fixes
Finding relevant fixes
Presenting found fixes

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 17
Collecting Example Fixes
Goal:
Build a database of example bug fixes that
take code from a broken into a fixed state.
(With minimal user intervention.)

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 18
Collecting Example Fixes
Possible approaches:
Web search

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 19
Collecting Example Fixes
Possible approaches:
Web search
Mining version control repositories
BugMem, Kim, SIGSOFT’06;
Dynamine, Livshits, SIGSOFT’05

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 20
Collecting Example Fixes
Possible approaches:
Web search
Mining version control repositories
BugMem, Kim, SIGSOFT’06;
Dynamine, Livshits, SIGSOFT’05

Instrumenting IDEs
inGimp, Terry, CHI’08
CommunityCommands, Matejka, UIST’09
Photoshop Tutorials by Demonstration, Grabler, SIGGRAPH’09

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 21
Collecting Example Fixes
Approach:
Instrument programmers’ IDEs to
automatically collect errors and source
code changes that correct those errors.
(Caveat: no logic bugs)

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 22
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 23
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 24
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 25
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 26
How do we find the right source pairs?

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 27
Tracking compile-time errors

Save source and error message at each compilation


Look for transitions from broken to error-free state

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 28
Tracking runtime errors

Progress heuristic
If the code makes progress past the
previous point of error,
mark error as resolved

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 29
Tracking runtime errors
Implementation
1. At runtime, count how often each line is executed
2. On error, store line’s execution count
3. On next run, if count for error line exceeds previous
count, mark as resolved.

Important assumptions
1. Errors cause uncaught exception
2. Identical input across executions

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 30
Three Steps
Collecting example fixes
Finding relevant fixes
Presenting found fixes

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 31
Finding Relevant Fixes
Goal:
Given a user’s broken code, find most
relevant examples in the fix database.

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 32
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 33
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 34
Finding Relevant Fixes
Approach:
Use both error message and source code
structure to search for relevant fixes.

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 35
Determining similarity

patch

User’s code Example Example


(broken) (broken) (fixed)

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 36
Determining similarity

similar to ?
User’s code Example
(broken) (broken)

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 37
Finding fixes for compiler errors

Naive implementation:
Look at code surrounding error and
compute string edit distance.

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 38
Finding fixes for compiler errors

Better:
Match on code structure, not text.

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 39
Finding fixes for compiler errors

Better: match on structure, not text

Replace identifiers with lexical analyzer.


Assumption: Locality (i.e., fix is near error)

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 40
Finding fixes for exceptions
Can we use the same approach for code
with runtime errors?
No, because such errors lack locality.

String s = null; root cause


//...
//...
System.out.println(s); exception

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 41
Architecture Outline
Collecting example fixes
Finding relevant fixes
Presenting found fixes

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 42
Present found fixes
Goal:
Present fixes to users in a way that
facilitates reasoning about relevance &
applicability to their own code

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 43
Applying found fixes

: : ?
Example Example User’s code
(broken) (fixed) (broken)

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 44
Present found fixes
Approach:
1. Show before-after comparison
2. Offer explanations
3. Attempt to patch users’ code
where possible

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 45
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 46
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 47
Where do these explanations
come from?

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 48
Crowdsource them
from experts.

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 49
How can we best encourage
experts to contribute?

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 50
We ensure their efforts have
maximum impact.

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 51
Priority list of frequently returned fixes

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 52
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 53
Applying found fixes

patch patch
?
Example Example User’s code
(broken) (fixed) (broken)

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 54
Applying patches automatically

float [] A = new float[];


float [] Z = new float[10];

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 55
Applying patches automatically

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 56
Feasibility Study

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 57
Guiding Questions
What size database is needed to return
useful suggestions?
How useful are suggestions collected
through instrumentation?
Which types of errors are covered?
Which aren’t?

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 58
Method

2 workshops on Processing at California College of Art


8 participants; 39 person-hours of usage

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 59
Self-Report Data

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 60
Database Seeded with Textbook Examples

image: arkadian.eu

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 61
Results: Common errors
274 queries (7 per person/hour)
84% returned at least one suggestion

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 62
How useful are suggestions?
Manual analysis of queries and returned
suggestions:
Does at least one of the top 3 returned
suggestions lead to a solution?

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 63
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 64
HelpMeOut gave users a helpful
suggestion half of the time.

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 65
Analysis

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 66
Can’t smarter editors solve these problems?

Structured & syntax directed editors can


prevent syntax errors...
Cornell Programm Synthesizer, Teitelbaum
Scratch, Resnick, CAMC’09

...but they increase the viscosity of code.


Constant background compilation with
error hinting aids syntax error correction.

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 67
Future work

dynamic languages
suggest improvements
other authoring domains

HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 68
HelpMeOut - What Would Other Programmers Do? Suggesting Solutions to Error Messages 69
bjoern@eecs.berkeley.edu
bid.berkeley.edu

You might also like