• Keine Ergebnisse gefunden

API Design Checklist

N/A
N/A
Protected

Academic year: 2022

Aktie "API Design Checklist"

Copied!
22
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)
(2)
(3)

API Design Checklist

Ten questions to ask before designing an API

@JaroslavTulach

NetBeans Platform Architect Oracle

(4)

Motto

Just like there is a difference between describing a house

and describing a Universe, there is a difference between

writing a code and producing an API.

(5)

About Me

1996 – Xelfi @ MatFyz

1997 – Initial NetBeans APIs

1999 – Acquired by Sun Microsystems

2008 - Practical API Design book

2010 – Acquired by Oracle

NetBeans & JDeveloper

2012 – 20 API Paradoxes book

now – HTML/Java APIs – e.g. @DukeScript

(6)

Program Agenda

What is my API?

How does a good API look?

Is my API correct?

Is my API misleading its users?

Am I egocentric?

1 2 3 4 5

(7)

Program Agenda

Am I sustainer or developer?

Is my API easy to use?

How do I accept patches?

Do I hide own garbage?

Am I ready for future?

6 7 8 9 10

(8)

What is my API?

• Is API about REST and JSON?

– Popular these days

– “API is not enough, protocols are everything!” - upside down

• API is “everything somebody else may depend on”

– Javadoc is not the only API you have

– Files layout, properties, ports, protocols, behavior, memory – Private fields? Reflection? sun.misc package?

• Stability categories

– Stable/Under Development/Friend/Private/Deprecated

(9)

How does a good API look?

• Coolness

– Be able attract attention

• Time to Market

– Ready for cluelessness

– Productive Quickly – archetypes, wizards & tools

• Preservation of Investments

– Backward compatibility – Track record important

(10)

Demo

Get started with @DukeScript wizard!

(11)

Is my API correct?

• It is correct because it exists!

– Shouldn't the API satisfy some goal?

• Working backwards

– Press release – high level description

http://wiki.apidesign.org/wiki/JerseyFaces

– Manual – use-cases

– FAQ – converting use-cases to action – The actual classes, methods & Javadoc

• Top-down verification

(12)

Demo

JerseyFaces press release

(13)

Is my API misleading its users?

• Things should have a single meaning

• Clarity of access modifiers

public final

protected abstract

protected final

• Clarity of types

Client API – use final class

Service Provider Interfaces – use interface

Evolution story

(14)

Demo

HTML/Java Audio API & SPI

(15)

Am I egocentric?

• Optimize for API writer or user?

One write vs. millions of users

• Does beauty matter?

API use should lead to beautiful code

• API needs to be stable & its internals reliable

Avoid visible refactorings

Be ready to hack

Bytecode patching

Dependency rewrites

(16)

Am I sustainer or developer?

• API design is art

No, it is engineering

• No repeating release cycles

• Creativity while working on first version

Prepare your evolution story

• Switch to sustaining mode

Compatibility #1 constraint

• Testing for compatibility

Binary: sigtest

(17)

Is my API easy to use?

• Usability study @apiusabilitytst

http://wiki.netbeans.org/Html4JavaUXStudy2014

Newcomer experience only

Can optimize “time to market”

• Comparing complexity of code

@DukeScript Java code shorter than original JavaScript

• Testability

@DukeScript application logic fully unit testable

(18)

Demo

Short and testable DukeScript code

(19)

How do I accept patches?

• Reaching limits of one's API

Force forks? Encourage hacks? Accept patches?

• I don't like your patch – artistic approach

Sure you don't as it is mine! But why wouldn't you accept it?

“Does not fit in the spirit”, “Would need careful review”, “Busy now”, etc.

• Your patch is not good enough – public API review process

Backward compatible

Documented

Tested

Ready for evolution

(20)

Do I hide my garbage?

• Javadoc for everything?

No, just for API packages

• Minimize conceptual surface

API classes should not expose implementation ones

Client API should not expose SPI interface

• Modules

Versioning

Semantic versioning – range dependencies

Enforcing public/private packages

(21)

Am I ready for the future?

• Your API is wrong!

Your API is definitely wrong!

• Get your evolution story right!

Client API needs new methods

Service provider interfaces cannot change

• There will be deprecations

Define reasonable end of life policy

Transfer API into different stability category

• Patching bytecode, classloading tricks & co.

(22)

The Checklist

API Stability categories assigned

Optimized for Time to Market

Future press release written

Criteria for accepting patches published

API elements have a single meaning

Ready to sacrifice myself not users

API evolution story defined

Implementation classes/packages hidden

Testing signature compatibility

End of life policy

Referenzen

ÄHNLICHE DOKUMENTE

Results: We present preterm twins whose mother was treated with venlafaxine, a nonselective serotonin reuptake inhibitor, throughout pregnancy until delivery.. The twins

(single-label tree with additional node info, e.g. node type) Elements, attributes, and text values are nodes. DOM parsers load XML into main memory random access by traversing

insert new node v as k-th child of p Insert and delete are inverse edit operations (i.e., insert undoes delete and vice versa).

Als aller erstes stellte Deutschland die zwei Logoentwürfe vor und alle Länder stimmten ab, welches ab sofort als offizielles Logo für unser Erasmus + Projekt

Wo du dich heute auch siehst, wir sind so froh, dass du hier bist, und wir hoffen, dass du im August dabei bist, um mehr über Mose und die Reise, die Gott für uns geplant hat,

When a sentence with a modal verb with subjectively epistemic meaning does contain a negation, the negation is morphological.. Modal verbs with objectively epistemic meaning can

Hegel’s idea of subjectivity liberating itself in the course of history served, in Ferdinand Christian Baur’s “Christianity and the Christian Church,”17 as the paradigm for

Hence, equation (15) demonstrates that the balanced growth rate is the higher, the smaller public deficits and public debt are. The highest balanced growth rate is obtained for