API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf ·...

22

Transcript of API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf ·...

Page 1: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files
Page 2: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files
Page 3: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

API Design ChecklistTen questions to ask before designing an API

@JaroslavTulachNetBeans Platform ArchitectOracle

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Page 4: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Motto

4

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.

Page 5: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

5

Page 6: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

6

Page 7: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

7

Page 8: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

8

Page 9: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

9

Page 10: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Demo

10

Get started with @DukeScript wizard!

Page 11: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

11

Page 12: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Demo

12

JerseyFaces press release

Page 13: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

13

Page 14: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Demo

14

HTML/Java Audio API & SPI

Page 15: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

15

Page 16: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

16

Page 17: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

17

Page 18: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Demo

18

Short and testable DukeScript code

Page 19: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

19

Page 20: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

20

Page 21: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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.

21

Page 22: API Design Checklist - JKUssw.jku.at/.../SpezialLVA/Modularity/CON4946_Tulach-APICheckList.pdf · 1997 – Initial NetBeans APIs ... –Javadoc is not the only API you have –Files

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

22