Designing and Documenting APIs Brad Myers 05-899D: Human Aspects of Software Development (HASD) Spring, 2011 1 Copyright © 2011 – Brad Myers.

Slides:



Advertisements
Similar presentations
Tutorial 6 Creating a Web Form
Advertisements

Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
API Design CPSC 315 – Programming Studio Fall 2008 Follows Kernighan and Pike, The Practice of Programming and Joshua Bloch’s Library-Centric Software.
Building Enterprise Applications Using Visual Studio ®.NET Enterprise Architect.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
UI Standards & Tools Khushroo Shaikh.
Programming in Java CSE301 Half Lecture Harry Erwin, PhD University of Sunderland.
Reasons to study concepts of PL
Report of the CMU Natural Programming Group Brad Myers, Andy Ko, Jeff Stylos, Michael Coblenz, Brian Ellis, Polo Chao Carnegie Mellon University.
Apache Axis: A Set of Java Tools for SOAP Web Services.
Usable Privacy and Security Carnegie Mellon University Spring 2008 Lorrie Cranor 1 Designing user studies February.
Creating Architectural Descriptions. Outline Standardizing architectural descriptions: The IEEE has published, “Recommended Practice for Architectural.
Advanced User Interface Software Brad Myers Human Computer Interaction Institute Spring, 2009.
ASP.NET Programming with C# and SQL Server First Edition
Course Instructor: Aisha Azeem
Architectural Design Establishing the overall structure of a software system Objectives To introduce architectural design and to discuss its importance.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Evaluation in HCI Angela Kessell Oct. 13, Evaluation Heuristic Evaluation Measuring API Usability Methodology Matters: Doing Research in the Behavioral.
The chapter will address the following questions:
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMING PRACTICES API documentation.
Problems with reuse – Increased maintenance costs; lack of tool support; not-invented- here syndrome; creating, maintaining, and using a component library.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
 A set of objectives or student learning outcomes for a course or a set of courses.  Specifies the set of concepts and skills that the student must.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
© Drexel University Software Engineering Research Group (SERG) 1 Based on the paper by Philippe Kruchten from Rational Software.
M1G Introduction to Programming 2 4. Enhancing a class:Room.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Lesley Bross, August 29, 2010 ArcGIS 10 add-in glossary.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Team Skill 6: Building the Right System From Use Cases to Implementation (25)
Presented by Abirami Poonkundran.  Introduction  Current Work  Current Tools  Solution  Tesseract  Tesseract Usage Scenarios  Information Flow.
Lecture 9: Chapter 9 Architectural Design
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
11 Partnership for Performance How to hear this lecture Click on the icon: to hear the narration for each slide.
Hipikat: A Project Memory for Software Development The CISC 864 Analysis By Lionel Marks.
1 Documenting with Javadoc. 2 Motivation  Why document programs? To make it easy to understand, e.g., for reuse and maintenance  What to document? Interface:
SEG3120 User Interfaces Design and Implementation
CSE 219 Computer Science III Program Design Principles.
Approaching a Problem Where do we start? How do we proceed?
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Refactoring1 Improving the structure of existing code.
Presented by: Ashgan Fararooy Referenced Papers and Related Work on:
Active Code Completion Cyrus Omar Computer Science School of Computer Science Carnegie Mellon University [ICSE12] YoungSeok Yoon Software Engineering Brad.
Object Oriented Software Development
 What are CASE Tools ?  Rational ROSE  Microsoft Project  Rational ROSE VS MS Project  Virtual Communication  The appropriate choice for ALL Projects.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Preliminary Ocean Project Page 1 WGISS SG May 15, C. Caspar G. Tandurella P. Goncalves G. Fallourd I. Petiteville Preliminary Ocean Project Phase.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Architecture View Models A model is a complete, simplified description of a system from a particular perspective or viewpoint. There is no single view.
Design Reuse Earlier we have covered the re-usable Architectural Styles as design patterns for High-Level Design. At mid-level and low-level, design patterns.
GoodOO Programming Practice in Java © Allan C. Milne v
CSPC 464 Fall 2014 Son Nguyen.  Attendance/Roster  Introduction ◦ Instructor ◦ Students  Syllabus  Q & A.
ICM – API Server & Forms Gary Ratcliffe.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Formal Specification: a Roadmap Axel van Lamsweerde published on ICSE (International Conference on Software Engineering) Jing Ai 10/28/2003.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Refactoring1 Improving the structure of existing code.
1 G52IWS: Web Services Description Language (WSDL) Chris Greenhalgh
Software Design and Development Development Methodoligies Computing Science.
6. (supplemental) User Interface Design. User Interface Design System users often judge a system by its interface rather than its functionality A poorly.
JavaScript, Sixth Edition
Lecture 20: API Usability
Advanced Programing practices
Chapter 11 Object-Oriented Design
Improving the structure of existing code
Advanced Programing practices
Presentation transcript:

Designing and Documenting APIs Brad Myers D: Human Aspects of Software Development (HASD) Spring, Copyright © 2011 – Brad Myers

Carnegie Mellon University, School of Computer Science APIs “Application Programming Interface” Frameworks, Libraries, Toolkits, SDK (Software Development Kits), etc. Also, internal APIs in a large software project User interface to the developer for the body of functionality Also relevant: API documentation, IDE support Support code reuse, information hiding and security/protection Virtually all coding today is done with APIs 2

Carnegie Mellon University, School of Computer Science Why Are APIs hard to use? Very large: Java 1.5 JDK: 4,000 classes with 30,000 methods Microsoft.NET 2.0: 140,000 classes, methods, properties & fields Services supplied by APIs are increasingly complex UI toolkits: buttons have gradients, hover highlights, animations Networking protocols Using APIs often requires adhering to complex protocols E.g., a method that can only be called after object is initialized Coordinating multiple objects together: Java Mail: Message and Transport APIs can be badly designed Poor names Inconsistent 3

Carnegie Mellon University, School of Computer Science Studies of API Usability Issue: confounded with functionality of API Can it even do what I want? “Work-arounds” But usually, it can – you just have to find it Various types of studies Not discussing “how to’s” based on “experience” and opinion Joshua Bloch about Java [2001] and Krzysztof Cwalina from Microsoft [2005] Modern studies started with Steven Clarke of Microsoft 4

Carnegie Mellon University, School of Computer Science Quality attributes of APIs Ref: Stylos PhD thesis or Stylos Design Dimensions paper Attributes affect different stakeholders Tradeoffs 5

Carnegie Mellon University, School of Computer Science API Design Decisions 6

Carnegie Mellon University, School of Computer Science Steven Clarke’s card-sort study Steven Clarke. (2011). How usable are your APIs? In Making Software: What really works and why we believe it, Andy Oram and Greg Wilson (eds), Wrote functionality for APIs on cards, asked developers to sort into classes Result: no agreement among sortings Lesson: usability is not about the API as a whole Developers rarely need to deal with the overall “architecture” of an API Not an issue of “scale” Question is: how does the API work for a particular task Supported by Stylos study Number of methods in a class does not correlate with complexity, but rather is the guessability of the name and where the methods are 7

Carnegie Mellon University, School of Computer Science Study of Visual Basic.Net 8 experienced Visual Basic 6 programmers all failed to be able use Visual Basic.Net Classic Usability techniques: video analysis, highlight tapes to design team, (blame the user, blame the documentation) Used cognitive dimensions to analyze why it was so difficult Abstraction level, learning style, working framework, work- step unit, progressive evaluation, premature commitment, penetrability, elaboration, viscosity, consistency, role expressiveness, domain correspondence E.g., StreamWriter, StreamReader instead of FileObject 8

Carnegie Mellon University, School of Computer Science “Personas” of Developers Opportunistic Developers Rapid experimentation, task-focused Prefer APIs with aggregate, high-level functions Pragmatic Developers Code-focused approach, used tools that helped focus on robustness and correctness of code Systematic Developers Defensive approach, want deep understanding before start working with it Prefer low-level, primitive functions Very different needs in APIs, and documentation 9

Carnegie Mellon University, School of Computer Science Stylos and Clarke’s Required Parameters in Constructors [Stylos & Clarke, ICSE’07] Compared create-set-call (default constructor) var foo = new FooClass(); foo.Bar = barValue; foo.Use(); vs. required constructors: var foo = new FooClass(barValue); foo.Use(); Tried to recruit Opportunistic (VB), Pragmatic (C#) and Systematic Developers (C++) Task 1: write the code in NotePad – elicited expectations Task 2 & 3: Use VS to create real code Different versions of File, Mail and Generic APIs (with and without required parameters) – real File class as no default constructors Task 4: Debug: bug is wrong value to the constructor Task 5: Programmers choose which constructor to use Task 6: reading code 10

Carnegie Mellon University, School of Computer Science Results: All informal – no measures were evaluated All participants assumed there would be a default constructor opportunistic and pragmatic would assume syntax error for compiler messages Required constructors interfered with learning Want to experiment with what kind of object to use first Did not insure valid objects – passed in null Preferred to not use temporary variables No effect on debugging or reading Optional extra constructors were useful 11

Carnegie Mellon University, School of Computer Science Results, cont: Model of Behavior 12

Carnegie Mellon University, School of Computer Science Brad A. Myers, CMU “Factory” Pattern Ref: [Ellis 2007] Instead of “normal” creation: Widget w = new Widget(); Objects must be created by another class: AbstractFactory f = AbstractFactory.getDefault(); Widget w = f.createWidget(); Also, factory method: Widget w = Widget.create(); Used frequently in Java (>61) and.Net (>13) and SAP Designed to get both descriptive and numeric results Within subject and between subject measures Lab study with expert Java programmers Five programming and debugging tasks 1: Notepad design of API 2: Use API – only factory pattern constructors 3: “Thingy” – with 2 subclasses, one with and one without 4. Debug task – between subjects 5. Use (almost) real Sockets

Carnegie Mellon University, School of Computer Science Results Notepad: no one designed a factory When no constructor, tried anyway, and even tried creating a subclass Time to develop using factories took 2.1 to 5.3 times longer compared to regular constructors (20:05 v 9:31, 7:10 v 1:20) All subjects had difficulties getting using factories in APIs Implications Avoid the factory pattern in APIs Documentation and tools can help developers find factories 14

Carnegie Mellon University, School of Computer Science Brad A. Myers, CMU Object Method Placement Ref: [Stylos FSE, 2008] Where to put functions when doing object-oriented design of APIs mail_Server.send( mail_Message ) vs. mail_Message.send( mail_Server ) Similar study design to previous When desired method is on the class that they start with, users were between 2.4 and 11.2 times faster (p < 0.05) Starting class can be predicted based on user’s tasks

Carnegie Mellon University, School of Computer Science Brad A. Myers, CMU Study of APIs for eSOA Ref: [Beaton, VL/HCC’08] Sponsored by SAP Study APIs for Enterprise Service-Oriented Architectures (“Web Services”) Client-server architecture organized into services using XML to communicate Enormously complex Requires significant flexibility and customizability Server Services Client XML WSDL Stub Code

Carnegie Mellon University, School of Computer Science Brad A. Myers, CMU eSOA Studies Results “Stub generators” that connect code to XML introduce complexities No sample code since multiple targets Naming problems: Too long Not understandable Differences in middle are frequently missed CustomerAddressBasicDataByNameAndAddressRequestMessageCustomerSelectionCommonNa me CustomerAddressBasicDataByNameAndAddressResponseMessageCustomerSelectionCommonN ame

Carnegie Mellon University, School of Computer Science Diagram of Documentation We made this diagram to understand doc. 18

Carnegie Mellon University, School of Computer Science Brad A. Myers, CMU eSOA Documentation Results Ref: [Jeong, IS-EUD 2009] Multiple paths: unclear which one to use Some paths were dead ends Inconsistent look and feel caused immediate abandonment of paths Hard to find required info. Business background helped

Carnegie Mellon University, School of Computer Science Another SAP study [Ref: Stylos, VL/HCC’08] Jeff Stylos studied SAP “Business Rules Framework Plus” API (BRFplus) as an intern in Walldorf, in summer 2007 Business rules allow EUD to specify behaviors, such as how tax is computed Identified customers’ real needs Found mismatch of abstraction level Designed wrapper API Dramatically better success than original Brad A. Myers, CMU

Carnegie Mellon University, School of Computer Science Robillard API Learning Studies [2009] Obstacles at Microsoft to learning APIs Surveys and in-person interviews of 440 developers Exploratory survey, qualitative interviews, follow-up survey Found mostly documentation problems Documentation of intent How supposed to be used; why designed a particular way Code examples needed, but must be right size = 1 task Matching APIs with scenarios (developer’s tasks) Penetrability of the API – about internal workings; performance Format and presentation – too thorough when obvious Also, API structure & naming itself 21

Tools to Help with API Understanding – Documentation and IDE 22

Carnegie Mellon University, School of Computer Science Jadeite Ref: [Stylos, VL/HCC’09] Jadeite: Java API Documentation with Extra Information Tacked-on for Emphasis Fix JavaDoc to help address these problems Focus attention on most popular packages and classes using font size “Placeholders” for methods that users want to exist Automatically extracted code examples for way to create classes and related classes Improved performance by factor of 3 Brad A. Myers, CMU

Carnegie Mellon University, School of Computer Science Apatite Documentation Tool Ref: [Eisenberg, VL/HCC’10] Apatite: Associative Perusing of APIs That Identifies Targets Easily Start with verbs (actions) and properties and find what classes implement them Find things associated with other things E.g., classes that are often used together Classes that implement or are used by a method Brad A. Myers, CMU

Carnegie Mellon University, School of Computer Science Calcite: Eclipse Plugin Ref: [Mooty, VL/HCC’10] Calcite: Construction And Language Completion Integrated Throughout Code completion in Eclipse augmented with Jadeite’s information How to create objects of specific classes SSLSocket s = ??? Brad A. Myers, CMU

Carnegie Mellon University, School of Computer Science Calcite, cont. Also for placeholders Study improved users’ success rate by 40% Didn’t hurt when not helpful 26

Carnegie Mellon University, School of Computer Science Uri Dekel’s eMoose [ICSE’09] Pushes directives (rules or caveats) to users E.g., setClientId must be called first Often are requirements of protocols Also restrictions on parameters, locking, alternatives, limitations, side effects, performance, security, etc. He hand-tagged “several thousand” directives 27

Carnegie Mellon University, School of Computer Science eMoose, cont. Eclipse plug-in provides icon and tooltip when methods encountered User study: debugging and writing code where directives would help eMoose users much more successful 28

Carnegie Mellon University, School of Computer Science CodeTrail Ref: [Goldman & Miller, VL/HCC 2008] Collected field data using a recorder of four programmer’s Eclipse and Firefox use for 1-3 weeks Found 646 development-related web pages Reports a taxonomy of uses of web pages Connect Firefox browsing of documentation of APIs while in Eclipse Connects various sites as the documentation for methods Bookmarks between code and documentation Automatically changes peripheral views 29

Carnegie Mellon University, School of Computer Science Future Work Many open issues in API usability Controversial design issues discussed in forums: Java Exceptions: Whether to use checked versus unchecked exceptions. Returning null versus throwing an exception. Returning null versus returning an empty object (i.e., an empty string). Returning error codes versus throwing exceptions. Naming: using “Hungarian” notation. Naming: using namespaces to disambiguate name collisions. Naming: how to name an updated version of an old class or method. 30