SlideShare a Scribd company logo
public void saveAsMidi()
{
Player player = new Player();
Pattern pattern = new Pattern("A5q B5q C5q");
try {
player.saveMidi(pattern, new File("MySong.midi"));
} catch (IOException e)
{
// handle IO Exception
}
}
public void loadAndPlayMidi()
{
Player player = new Player();
try {
player.playMidiDirectly(new File("MySong.midi"));
} catch (IOException e)
{
// handle IO Exception
} catch (InvalidMidiDataException e)
{
// handle Invalid MIDI Data Exception
}
}
public void savePattern()
{
Pattern pattern = new Pattern("A5q B5q C5q");
try {
pattern.savePattern(new File("MusicString.jfugue"));
} catch (IOException e)
{
// handle IO Exception
}
}
public void loadPattern()
{
Player player = new Player();
Pattern pattern = null;
try {
pattern = Pattern.loadPattern(new File("MusicString.jfugue"));
player.play(pattern);
Golden Rules of API Design
David Koelle
davekoelle.com
July 19, 2011
Objectives
• Learn guidelines for creating a solid API
• Understand the importance of API Usability
• Consider how even the best-designed API needs to
be accompanied with clear documents and guides to
succeed
Overview
• Background and Definitions
• The Importance of API Usability
• Guidelines for API Design
• The Importance of Effective Communication in API
Usability
• Questions and Discussion
Overview
• Background and Definitions
• The Importance of API Usability
• Guidelines for API Design
• The Importance of Effective Communication in API
Usability
• Questions and Discussion
Speaker background
• David Koelle
• First computer: TI-99/4A in 2nd grade
• Graduate of Worcester Polytechnic Institute
(Massachusetts, USA)
• 14-year career spans large and small businesses and start-ups
• Three-time Java Rock Star for talks given at JavaOne
• David has developed APIs for:
• Music Programming (JFugue)
• User Interfaces
• Graphics and Animation
• Business Intelligence
• Social Network Analysis
Definitions
• An Application Programming Interface (API) is
comprised of the exposed code that other
developers use to access a program’s functionality
• Examples:
• JFugue API for music programming (Java)
• Google Maps API (JavaScript, Flash, and web services)
• API Usability is a set of guidelines for creating APIs
that others can understand and use effectively
Definitions of usability
“Usability is how easy, efficient, and pleasant
it is to use a service”
– Jacob Nielsen
“Usability is the effectiveness, efficiency, and satisfaction
with which specified users achieve specified goals
in particular environments”
– ISO-9241 (Ergonomics of Human System Interaction)
• These definitions come from the User Interface (UI)
community, but are applicable to API Design as well!
Components of API Usability
• API Usability is informed by good programming
practices and user interface design
Good
Programming
Practices
User
Interface
Design
API Usability
Components of API Usability
• Effective communication is also an important part of
getting an API used!
Good
Programming
Practices
User
Interface
Design
API Usability
Effective
Communication
Good programming practices
• To design a good API, you need to use good
development practices
• A good API will follow all of the guidance in Joshua
Bloch’s book, “Effective Java”. A selection:
• Item 13: Minimize the accessibility of classes and members
• Item 38: Check parameters for validity
• Item 56: Adhere to generally accepted naming conventions
• Item 64: Strive for failure atomicity
User interface design
• The most important question in user interface design
is: Who is the user?
• Who are the users of an API? Other developers!
• This should be a group that’s easy for us to understand
• You could get into “personas” if you want: “Mike is a 25-
year old college graduate who learned programming in
high school and reads a lot of xkcd…”
• You also need to know: What are the user’s goals?
• What will the user try to achieve by using your API?
• How will the user measure success?
• How can you help the user succeed?
Four principles for highly usable systems
(D. Norman)
• Good visibility: The possible actions, the states and
the alternatives for action must be exposed
• Good conceptual model: The use of helpful,
consistent and complete abstractions helping the
users to create a proper mental image model of the
system
• Good mapping between actions and results: Natural
mapping between actions and their results
• Good feedback about results of actions: Full and
continuous feedback about the results of actions
Metrics for evaluating usability of a system
(B. Schneiderman)
• Time to learn a system
• Speed of task execution
• Rate of errors
• Knowledge retention over time
• Subjective user satisfaction
Characteristics of a good API (J. Bloch)
• Easy to learn
• Easy to use, even without documentation
• Hard to misuse
• Easy to read and maintain code that uses it
• Sufficiently powerful to satisfy requirements
• Easy to extend
• Appropriate to audience
From Joshua Bloch’s “How to Design a Good API and Why it Matters”
Overview
• Background and Definitions
• The Importance of API Usability
• Guidelines for API Design
• The Importance of Effective Communication in API
Usability
• Questions and Discussion
Realize that publicizing an API
represents a commitment
• An API is a coding “contract”, and users of your API will
expect future versions to be compatible with released
versions
• It’s easy to add new functionality
• It’s hard to delete functionality
• This is why so many methods in the Java API are deprecated
• It’s just wrong to make a method to something
completely different between versions
• I’m glad I can’t come up with a good example for this one!
• This is the most important rule. The rest is all detail.
Begin with the end in mind
• Know what you want your API to achieve
• Mock up several sample applications that will use
your API before you start developing the API itself
• Develop your API using Test-Driven Development
Make conceptually easy things
simple to do
• Use the hidden layers of your API to offload
complexity from the end-user developer
• Example: Letting the user make an audible beep:
Bad API Good API
Open a sound data line
beep(int frequency)
Create a clip object
Generate bytes for the
frequencies
Send the clip to the data line
Close the data line
Make sure all variables are
cleaned up
Construct complete objects only
• Never allow a user to construct an object that is not
fully formed. Bad example:
Foo foo = new Foo();
foo.setCriticalValue(true); // This needs to be
set before the object can be used
• Two problems with this:
• Your API cannot force developers to call methods in a
predictable order
• Additional method calls require the user to learn about
those calls
• Make users think up front about what they need to
provide to create a complete object
Expose the minimum amount of code
• Learn how to use these Java keywords effectively:
Scope: public, private, protected (and package scope)
Modifiers: final, transient
• Using scope and modifiers properly helps users know
what they should and should not touch
• Realize that the more classes and methods you
publish, the more you’ll be accountable for in the
future
Be compact and concise
• Help the user derive the most benefit from the
fewest lines of code
• Example - play music in JFugue:
Player player = new Player();
player.play(“C D E F G A B”);
• Provide the smallest set of functionality in your code
that provides the most benefit
• You could write the “War and Peace” of APIs, and it might
be great, but no one would take the time to learn it all!
Be absolutely correct
• People rely on your API to do exactly what it says it
will do
• Make sure your API works correctly, and generates
correct output
Borrowed from Elliotte Rusty Harold’s
XOM Design Principles
Encode common patterns and
encourage best practices
• Notice when there code that you repeat over and
over in your sample programs
• This common pattern may be something that your users
will do, too
• Make the common code a part of your API
• Notice when you’ve identified the best way to
perform a task or achieve a goal with your API
• This may also be something your users will do
• Make the best practice a part of your API
Report errors immediately and clearly
• Report errors and exceptions as soon as they happen
• Guard against error-prone input by using assertions
at the beginning of a method
• Make errors as verbose as possible
• Bad example: “Can’t find file”
• Good example: “The file filename was not found in folder
folder name”
Overview
• Background and Definitions
• The Importance of API Usability
• Guidelines for API Design
• The Importance of Effective Communication in API
Usability
• Questions and Discussion
The importance of effective
communication in API Usability
• When designing an API, it’s important to use:
• Employ good programming practices
• Perform user interface design
• Now you have a quality API, and you want people to
use it. What next?
• Once the API is complete, your communication about
the API is critical to its success
Engage with the user community
• Allow users to communicate with you, and engage
your users in discussion
• Track requests and defects in a defect tracking
system (e.g., Google Code, Jira)
• Be responsive to email comments from users
• Publish a blog with discussions about your API
• When people contact you, ask them how they’re
using your API!
• You need to know what your users are doing, so you can
make effective changes to future versions of your API
• You may be delighted at some of the responses
Be open in communicating an
evolving API
• If you need to make changes to your published API,
be clear about it
• People with older versions of your API depend on
new versions acting the same way for existing
functionality
Provide clear support materials
• The success of your API project also depends on your
presentation of your material that markets the API:
• Documentation
• Website
• Discussion boards
• If someone goes to your webpage and can't figure
out what your API does, how to download it, how to
use it, and what some simple examples might be,
they probably won't use it
Finally: Delight your users
• Make sure your users enjoy using your API!
• Think of ways to make your API clever and well-
crafted
• Ensure your API anticipates the user’s needs by
providing easy access to features users want
• Prefer enjoyment through effective code as opposed
to humor in class and method names
• That comes off as a little tacky, and humor doesn’t always
translate well
Overview
• Background and Definitions
• The Importance of API Usability
• Guidelines for API Design
• The Importance of Effective Communication in API
Usability
• Questions and Discussion
Resources
• Joshua Bloch, “How to Design a Good API and Why it
Matters”
http://www.youtube.com/watch?v=aAb7hSCtvGw
• Joshua Bloch, “Effective Java”
http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683
• Bill Venners, “API Design with Java”
http://www.artima.com/apidesign/
• Five-part discussion with Bill Venners and Elliotte Rusty
Harold on API design for JDOM and XOM
Part 5: http://www.artima.com/intv/xomdesign.html
• Jaroslav Tulach, “Practical API Design” (Apress)
http://www.apress.com/9781430209737
public void saveAsMidi()
{
Player player = new Player();
Pattern pattern = new Pattern("A5q B5q C5q");
try {
player.saveMidi(pattern, new File("MySong.midi"));
} catch (IOException e)
{
// handle IO Exception
}
}
public void loadAndPlayMidi()
{
Player player = new Player();
try {
player.playMidiDirectly(new File("MySong.midi"));
} catch (IOException e)
{
// handle IO Exception
} catch (InvalidMidiDataException e)
{
// handle Invalid MIDI Data Exception
}
}
public void savePattern()
{
Pattern pattern = new Pattern("A5q B5q C5q");
try {
pattern.savePattern(new File("MusicString.jfugue"));
} catch (IOException e)
{
// handle IO Exception
}
}
public void loadPattern()
{
Player player = new Player();
Pattern pattern = null;
try {
pattern = Pattern.loadPattern(new File("MusicString.jfugue"));
player.play(pattern);
Thank You!
David Koelle
davekoelle.com
July 19, 2011

More Related Content

What's hot

TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
NexThoughts Technologies
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
Rotem Tamir
 
Api Testing
Api TestingApi Testing
Api Testing
Vishwanath KC
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
Theo Jungeblut
 
Asynchronous programming in C#
Asynchronous programming in C#Asynchronous programming in C#
Asynchronous programming in C#
Bohdan Pashkovskyi
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in javasawarkar17
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
Ahmed Ehab AbdulAziz
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
Udaya Kumar
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
SUDIP GHOSH
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
Ryan Cuprak
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
Solid principles
Solid principlesSolid principles
Solid principles
Monica Rodrigues
 
DVGA writeup
DVGA writeupDVGA writeup
DVGA writeup
Yu Iwama
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
Brad Genereaux
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
Samundra khatri
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
Haim Michael
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
Prem Sanil
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
Roman Liubun
 

What's hot (20)

TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
 
Api Testing
Api TestingApi Testing
Api Testing
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
 
1 .java basic
1 .java basic1 .java basic
1 .java basic
 
Asynchronous programming in C#
Asynchronous programming in C#Asynchronous programming in C#
Asynchronous programming in C#
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in java
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Solid principles
Solid principlesSolid principles
Solid principles
 
DVGA writeup
DVGA writeupDVGA writeup
DVGA writeup
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
 

Viewers also liked

Api anti patterns
Api anti patternsApi anti patterns
Api anti patterns
Mike Pearce
 
APIs: the Glue of Cloud Computing
APIs: the Glue of Cloud ComputingAPIs: the Glue of Cloud Computing
APIs: the Glue of Cloud Computing
3scale
 
The hypermedia api
The hypermedia apiThe hypermedia api
The hypermedia apiInviqa
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
Mario Cardinal
 
Questions product managers should ask customers
Questions product managers should ask customersQuestions product managers should ask customers
Questions product managers should ask customers
ProductPlan
 
Real World API Business Models That Worked
Real World API Business Models That WorkedReal World API Business Models That Worked
Real World API Business Models That Worked
ProgrammableWeb
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
Stormpath
 
Welcome to the API Economy: Developing Your API Strategy
Welcome to the API Economy: Developing Your API StrategyWelcome to the API Economy: Developing Your API Strategy
Welcome to the API Economy: Developing Your API Strategy
MuleSoft
 
API Business Models
API Business ModelsAPI Business Models
API Business Models
John Musser
 
HATEOAS 101 - Opinionated Introduction to a REST API Style
HATEOAS 101 - Opinionated Introduction to a REST API StyleHATEOAS 101 - Opinionated Introduction to a REST API Style
HATEOAS 101 - Opinionated Introduction to a REST API Style
Apigee | Google Cloud
 

Viewers also liked (12)

Api anti patterns
Api anti patternsApi anti patterns
Api anti patterns
 
API Design - 3rd Edition
API Design - 3rd EditionAPI Design - 3rd Edition
API Design - 3rd Edition
 
APIs: the Glue of Cloud Computing
APIs: the Glue of Cloud ComputingAPIs: the Glue of Cloud Computing
APIs: the Glue of Cloud Computing
 
The hypermedia api
The hypermedia apiThe hypermedia api
The hypermedia api
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
Questions product managers should ask customers
Questions product managers should ask customersQuestions product managers should ask customers
Questions product managers should ask customers
 
Real World API Business Models That Worked
Real World API Business Models That WorkedReal World API Business Models That Worked
Real World API Business Models That Worked
 
RESTful API Design, Second Edition
RESTful API Design, Second EditionRESTful API Design, Second Edition
RESTful API Design, Second Edition
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
 
Welcome to the API Economy: Developing Your API Strategy
Welcome to the API Economy: Developing Your API StrategyWelcome to the API Economy: Developing Your API Strategy
Welcome to the API Economy: Developing Your API Strategy
 
API Business Models
API Business ModelsAPI Business Models
API Business Models
 
HATEOAS 101 - Opinionated Introduction to a REST API Style
HATEOAS 101 - Opinionated Introduction to a REST API StyleHATEOAS 101 - Opinionated Introduction to a REST API Style
HATEOAS 101 - Opinionated Introduction to a REST API Style
 

Similar to Golden Rules of API Design

Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIs
Peter Hendriks
 
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for Longevity
MuleSoft
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIsNLJUG
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
Peter Hendriks
 
Full stack conference talk slides
Full stack conference talk slidesFull stack conference talk slides
Full stack conference talk slides
Sameer Al-Sakran
 
Understanding and Executing on API Developer Experience
Understanding and Executing on API Developer ExperienceUnderstanding and Executing on API Developer Experience
Understanding and Executing on API Developer Experience
SmartBear
 
How to design effective APIs
How to design effective APIsHow to design effective APIs
How to design effective APIs
Bansilal Haudakari
 
Designing for efficiency.pdf
Designing for efficiency.pdfDesigning for efficiency.pdf
Designing for efficiency.pdf
Gabriela Véghová
 
API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...
SmartBear
 
The API Lifecycle Series: Evolving API Development and Testing from Open Sour...
The API Lifecycle Series: Evolving API Development and Testing from Open Sour...The API Lifecycle Series: Evolving API Development and Testing from Open Sour...
The API Lifecycle Series: Evolving API Development and Testing from Open Sour...
SmartBear
 
Understanding and Executing on API Developer Experience
Understanding and Executing on API Developer ExperienceUnderstanding and Executing on API Developer Experience
Understanding and Executing on API Developer Experience
Keshav Vasudevan
 
User Experience Bootcamp for Developers
User Experience Bootcamp for DevelopersUser Experience Bootcamp for Developers
User Experience Bootcamp for Developers
Catherine Robson
 
5 Keys to API Design - API Days Paris 2013
5 Keys to API Design - API Days Paris 20135 Keys to API Design - API Days Paris 2013
5 Keys to API Design - API Days Paris 2013Daniel Feist
 
Kevin Whinnery: Best Practices for Cross-Platform Mobile Development
Kevin Whinnery: Best Practices for Cross-Platform Mobile DevelopmentKevin Whinnery: Best Practices for Cross-Platform Mobile Development
Kevin Whinnery: Best Practices for Cross-Platform Mobile Development
Axway Appcelerator
 
Make Your Contribution Count. Adding Value to the API as a Technical Communic...
Make Your Contribution Count. Adding Value to the API as a Technical Communic...Make Your Contribution Count. Adding Value to the API as a Technical Communic...
Make Your Contribution Count. Adding Value to the API as a Technical Communic...
Petko Mikhailov
 
Building the Eventbrite API Ecosystem
Building the Eventbrite API EcosystemBuilding the Eventbrite API Ecosystem
Building the Eventbrite API Ecosystem
Mitch Colleran
 
E Learning Management System By Tuhin Roy Using PHP
E Learning Management System By Tuhin Roy Using PHPE Learning Management System By Tuhin Roy Using PHP
E Learning Management System By Tuhin Roy Using PHP
Tuhin Ray
 
How to design good api
How to design good apiHow to design good api
How to design good apiOsama Shakir
 
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias
 

Similar to Golden Rules of API Design (20)

Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIs
 
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for Longevity
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
Full stack conference talk slides
Full stack conference talk slidesFull stack conference talk slides
Full stack conference talk slides
 
SonarQube
SonarQubeSonarQube
SonarQube
 
Understanding and Executing on API Developer Experience
Understanding and Executing on API Developer ExperienceUnderstanding and Executing on API Developer Experience
Understanding and Executing on API Developer Experience
 
How to design effective APIs
How to design effective APIsHow to design effective APIs
How to design effective APIs
 
Designing for efficiency.pdf
Designing for efficiency.pdfDesigning for efficiency.pdf
Designing for efficiency.pdf
 
API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...
 
The API Lifecycle Series: Evolving API Development and Testing from Open Sour...
The API Lifecycle Series: Evolving API Development and Testing from Open Sour...The API Lifecycle Series: Evolving API Development and Testing from Open Sour...
The API Lifecycle Series: Evolving API Development and Testing from Open Sour...
 
Understanding and Executing on API Developer Experience
Understanding and Executing on API Developer ExperienceUnderstanding and Executing on API Developer Experience
Understanding and Executing on API Developer Experience
 
User Experience Bootcamp for Developers
User Experience Bootcamp for DevelopersUser Experience Bootcamp for Developers
User Experience Bootcamp for Developers
 
5 Keys to API Design - API Days Paris 2013
5 Keys to API Design - API Days Paris 20135 Keys to API Design - API Days Paris 2013
5 Keys to API Design - API Days Paris 2013
 
Kevin Whinnery: Best Practices for Cross-Platform Mobile Development
Kevin Whinnery: Best Practices for Cross-Platform Mobile DevelopmentKevin Whinnery: Best Practices for Cross-Platform Mobile Development
Kevin Whinnery: Best Practices for Cross-Platform Mobile Development
 
Make Your Contribution Count. Adding Value to the API as a Technical Communic...
Make Your Contribution Count. Adding Value to the API as a Technical Communic...Make Your Contribution Count. Adding Value to the API as a Technical Communic...
Make Your Contribution Count. Adding Value to the API as a Technical Communic...
 
Building the Eventbrite API Ecosystem
Building the Eventbrite API EcosystemBuilding the Eventbrite API Ecosystem
Building the Eventbrite API Ecosystem
 
E Learning Management System By Tuhin Roy Using PHP
E Learning Management System By Tuhin Roy Using PHPE Learning Management System By Tuhin Roy Using PHP
E Learning Management System By Tuhin Roy Using PHP
 
How to design good api
How to design good apiHow to design good api
How to design good api
 
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
 

Recently uploaded

A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 

Recently uploaded (20)

A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 

Golden Rules of API Design

  • 1. public void saveAsMidi() { Player player = new Player(); Pattern pattern = new Pattern("A5q B5q C5q"); try { player.saveMidi(pattern, new File("MySong.midi")); } catch (IOException e) { // handle IO Exception } } public void loadAndPlayMidi() { Player player = new Player(); try { player.playMidiDirectly(new File("MySong.midi")); } catch (IOException e) { // handle IO Exception } catch (InvalidMidiDataException e) { // handle Invalid MIDI Data Exception } } public void savePattern() { Pattern pattern = new Pattern("A5q B5q C5q"); try { pattern.savePattern(new File("MusicString.jfugue")); } catch (IOException e) { // handle IO Exception } } public void loadPattern() { Player player = new Player(); Pattern pattern = null; try { pattern = Pattern.loadPattern(new File("MusicString.jfugue")); player.play(pattern); Golden Rules of API Design David Koelle davekoelle.com July 19, 2011
  • 2. Objectives • Learn guidelines for creating a solid API • Understand the importance of API Usability • Consider how even the best-designed API needs to be accompanied with clear documents and guides to succeed
  • 3. Overview • Background and Definitions • The Importance of API Usability • Guidelines for API Design • The Importance of Effective Communication in API Usability • Questions and Discussion
  • 4. Overview • Background and Definitions • The Importance of API Usability • Guidelines for API Design • The Importance of Effective Communication in API Usability • Questions and Discussion
  • 5. Speaker background • David Koelle • First computer: TI-99/4A in 2nd grade • Graduate of Worcester Polytechnic Institute (Massachusetts, USA) • 14-year career spans large and small businesses and start-ups • Three-time Java Rock Star for talks given at JavaOne • David has developed APIs for: • Music Programming (JFugue) • User Interfaces • Graphics and Animation • Business Intelligence • Social Network Analysis
  • 6. Definitions • An Application Programming Interface (API) is comprised of the exposed code that other developers use to access a program’s functionality • Examples: • JFugue API for music programming (Java) • Google Maps API (JavaScript, Flash, and web services) • API Usability is a set of guidelines for creating APIs that others can understand and use effectively
  • 7. Definitions of usability “Usability is how easy, efficient, and pleasant it is to use a service” – Jacob Nielsen “Usability is the effectiveness, efficiency, and satisfaction with which specified users achieve specified goals in particular environments” – ISO-9241 (Ergonomics of Human System Interaction) • These definitions come from the User Interface (UI) community, but are applicable to API Design as well!
  • 8. Components of API Usability • API Usability is informed by good programming practices and user interface design Good Programming Practices User Interface Design API Usability
  • 9. Components of API Usability • Effective communication is also an important part of getting an API used! Good Programming Practices User Interface Design API Usability Effective Communication
  • 10. Good programming practices • To design a good API, you need to use good development practices • A good API will follow all of the guidance in Joshua Bloch’s book, “Effective Java”. A selection: • Item 13: Minimize the accessibility of classes and members • Item 38: Check parameters for validity • Item 56: Adhere to generally accepted naming conventions • Item 64: Strive for failure atomicity
  • 11. User interface design • The most important question in user interface design is: Who is the user? • Who are the users of an API? Other developers! • This should be a group that’s easy for us to understand • You could get into “personas” if you want: “Mike is a 25- year old college graduate who learned programming in high school and reads a lot of xkcd…” • You also need to know: What are the user’s goals? • What will the user try to achieve by using your API? • How will the user measure success? • How can you help the user succeed?
  • 12. Four principles for highly usable systems (D. Norman) • Good visibility: The possible actions, the states and the alternatives for action must be exposed • Good conceptual model: The use of helpful, consistent and complete abstractions helping the users to create a proper mental image model of the system • Good mapping between actions and results: Natural mapping between actions and their results • Good feedback about results of actions: Full and continuous feedback about the results of actions
  • 13. Metrics for evaluating usability of a system (B. Schneiderman) • Time to learn a system • Speed of task execution • Rate of errors • Knowledge retention over time • Subjective user satisfaction
  • 14. Characteristics of a good API (J. Bloch) • Easy to learn • Easy to use, even without documentation • Hard to misuse • Easy to read and maintain code that uses it • Sufficiently powerful to satisfy requirements • Easy to extend • Appropriate to audience From Joshua Bloch’s “How to Design a Good API and Why it Matters”
  • 15. Overview • Background and Definitions • The Importance of API Usability • Guidelines for API Design • The Importance of Effective Communication in API Usability • Questions and Discussion
  • 16. Realize that publicizing an API represents a commitment • An API is a coding “contract”, and users of your API will expect future versions to be compatible with released versions • It’s easy to add new functionality • It’s hard to delete functionality • This is why so many methods in the Java API are deprecated • It’s just wrong to make a method to something completely different between versions • I’m glad I can’t come up with a good example for this one! • This is the most important rule. The rest is all detail.
  • 17. Begin with the end in mind • Know what you want your API to achieve • Mock up several sample applications that will use your API before you start developing the API itself • Develop your API using Test-Driven Development
  • 18. Make conceptually easy things simple to do • Use the hidden layers of your API to offload complexity from the end-user developer • Example: Letting the user make an audible beep: Bad API Good API Open a sound data line beep(int frequency) Create a clip object Generate bytes for the frequencies Send the clip to the data line Close the data line Make sure all variables are cleaned up
  • 19. Construct complete objects only • Never allow a user to construct an object that is not fully formed. Bad example: Foo foo = new Foo(); foo.setCriticalValue(true); // This needs to be set before the object can be used • Two problems with this: • Your API cannot force developers to call methods in a predictable order • Additional method calls require the user to learn about those calls • Make users think up front about what they need to provide to create a complete object
  • 20. Expose the minimum amount of code • Learn how to use these Java keywords effectively: Scope: public, private, protected (and package scope) Modifiers: final, transient • Using scope and modifiers properly helps users know what they should and should not touch • Realize that the more classes and methods you publish, the more you’ll be accountable for in the future
  • 21. Be compact and concise • Help the user derive the most benefit from the fewest lines of code • Example - play music in JFugue: Player player = new Player(); player.play(“C D E F G A B”); • Provide the smallest set of functionality in your code that provides the most benefit • You could write the “War and Peace” of APIs, and it might be great, but no one would take the time to learn it all!
  • 22. Be absolutely correct • People rely on your API to do exactly what it says it will do • Make sure your API works correctly, and generates correct output Borrowed from Elliotte Rusty Harold’s XOM Design Principles
  • 23. Encode common patterns and encourage best practices • Notice when there code that you repeat over and over in your sample programs • This common pattern may be something that your users will do, too • Make the common code a part of your API • Notice when you’ve identified the best way to perform a task or achieve a goal with your API • This may also be something your users will do • Make the best practice a part of your API
  • 24. Report errors immediately and clearly • Report errors and exceptions as soon as they happen • Guard against error-prone input by using assertions at the beginning of a method • Make errors as verbose as possible • Bad example: “Can’t find file” • Good example: “The file filename was not found in folder folder name”
  • 25. Overview • Background and Definitions • The Importance of API Usability • Guidelines for API Design • The Importance of Effective Communication in API Usability • Questions and Discussion
  • 26. The importance of effective communication in API Usability • When designing an API, it’s important to use: • Employ good programming practices • Perform user interface design • Now you have a quality API, and you want people to use it. What next? • Once the API is complete, your communication about the API is critical to its success
  • 27. Engage with the user community • Allow users to communicate with you, and engage your users in discussion • Track requests and defects in a defect tracking system (e.g., Google Code, Jira) • Be responsive to email comments from users • Publish a blog with discussions about your API • When people contact you, ask them how they’re using your API! • You need to know what your users are doing, so you can make effective changes to future versions of your API • You may be delighted at some of the responses
  • 28. Be open in communicating an evolving API • If you need to make changes to your published API, be clear about it • People with older versions of your API depend on new versions acting the same way for existing functionality
  • 29. Provide clear support materials • The success of your API project also depends on your presentation of your material that markets the API: • Documentation • Website • Discussion boards • If someone goes to your webpage and can't figure out what your API does, how to download it, how to use it, and what some simple examples might be, they probably won't use it
  • 30. Finally: Delight your users • Make sure your users enjoy using your API! • Think of ways to make your API clever and well- crafted • Ensure your API anticipates the user’s needs by providing easy access to features users want • Prefer enjoyment through effective code as opposed to humor in class and method names • That comes off as a little tacky, and humor doesn’t always translate well
  • 31. Overview • Background and Definitions • The Importance of API Usability • Guidelines for API Design • The Importance of Effective Communication in API Usability • Questions and Discussion
  • 32. Resources • Joshua Bloch, “How to Design a Good API and Why it Matters” http://www.youtube.com/watch?v=aAb7hSCtvGw • Joshua Bloch, “Effective Java” http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683 • Bill Venners, “API Design with Java” http://www.artima.com/apidesign/ • Five-part discussion with Bill Venners and Elliotte Rusty Harold on API design for JDOM and XOM Part 5: http://www.artima.com/intv/xomdesign.html • Jaroslav Tulach, “Practical API Design” (Apress) http://www.apress.com/9781430209737
  • 33. public void saveAsMidi() { Player player = new Player(); Pattern pattern = new Pattern("A5q B5q C5q"); try { player.saveMidi(pattern, new File("MySong.midi")); } catch (IOException e) { // handle IO Exception } } public void loadAndPlayMidi() { Player player = new Player(); try { player.playMidiDirectly(new File("MySong.midi")); } catch (IOException e) { // handle IO Exception } catch (InvalidMidiDataException e) { // handle Invalid MIDI Data Exception } } public void savePattern() { Pattern pattern = new Pattern("A5q B5q C5q"); try { pattern.savePattern(new File("MusicString.jfugue")); } catch (IOException e) { // handle IO Exception } } public void loadPattern() { Player player = new Player(); Pattern pattern = null; try { pattern = Pattern.loadPattern(new File("MusicString.jfugue")); player.play(pattern); Thank You! David Koelle davekoelle.com July 19, 2011