10. BigDecimal
public BigDecimal(double val)
Translates a double into a BigDecimal which is the exact
decimal representation of the double's binary floating-
point value. The scale of the returned BigDecimal is the
smallest value such that (10scale × val) is an integer.
http://docs.oracle.com/javase/6/docs/api/java/math/BigDecimal.html
11
13. “The greatest obstacle to learning an
API … is insufficient or inadequate
examples”
Martin Robillard. What Makes APIs Hard to Learn? Answers
from Developers. IEEE Software, 26(6):27-34, 2009.
14. The Rest of this Talk
What makes a
good example?
Motivation
Approach: Example Synthesis Evaluation
15
15. The Rest of this Talk
What makes a
good example?
Approach: Example Synthesis Evaluation
16
18. Research Tools
• MAPO
– H. Zhong, T. Xie, L. Zhang, J. Pei, and H. Mei,
“MAPO: Mining and recommending API usage
patterns,” in European Conference on Object-
Oriented Programming, 2009.
• eXoaDocs
– J. Kim, S. Lee, S. Hwang, and S. Kim, “Towards an
intelligent code search engine,” in AAAI
Conference on Artificial Intelligence, 2010.
19
19. Research Tools
• MAPO
– H. Zhong, T. Xie, L. Zhang, J. Pei, and H. Mei,
“MAPO: Mining and recommending API usage
patterns,” in European Conference on Object-
Oriented Programming, 2009.
• eXoaDocs
– J. Kim, S. Lee, S. Hwang, and S. Kim, “Towards an
intelligent code search engine,” in AAAI
Conference on Artificial Intelligence, 2010.
20
33. Two Key Insights
Abstraction
Operator
Dataflow Analysis Abstraction
34. Search Term
Software “BufferedReader”
Corpus Control Flow
<init> Graph
Representation
ready
Miner
readLine
print
close
35
35. argument
Search Term argument
“foo.txt”
Software FileReader
“BufferedReader”
Corpus
<init> identifier
br
ready
Miner predicate
ready()
readLine
returns
String:
line
print
With Dataflow argument
Annotations Relevant line
to Documentation close
36
47. Examples
Calendar calendar = Calendar.getInstance();
Date d = calendar.getTime();
//Do something with d
Query: java.util.Calendar
48
48. Examples
String regex; //initialized previously
String input; //initialized previously
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(input);
//Do something with m
Query: java.util.regex.Pattern
49
49. Limitations
• Can’t always be perfectly precise
– E.g., Aliasing, Types
– Conservative analysis preserves correctness
• Common usage is not always best
– E.g., poor exception handling
– Guarantee representative examples
• Not all APIs have indicative patterns
• Some patterns are difficult to find
– Message passing over network etc.
50
58. Future Work
• More Complex Queries
– How do I use X with Y ?
– Kuat Yessenov, Zhilei Xu, and Armando Solar-
Lezama, Data-driven synthesis for object-oriented
frameworks, OOPSLA, 2011.
• What does this example do?
– Symbolic execution of the example itself
• Additional Guarantees
– Proof Carrying Examples
59