User Interface Principles in API Design

26
User Interface Principles in API Design Elliotte Rusty Harold [email protected] http:// www.cafeaulait.org/

description

User Interface Principles in API Design. Elliotte Rusty Harold [email protected] http://www.cafeaulait.org/. Programmers Are People Too. Eat Like Humans Sleep Like Humans Mate Like Humans Think Like Humans. User Interface Design is a Science. - PowerPoint PPT Presentation

Transcript of User Interface Principles in API Design

Page 1: User Interface Principles in API Design

User Interface Principles in API Design

Elliotte Rusty Harold

[email protected]

http://www.cafeaulait.org/

Page 2: User Interface Principles in API Design

Programmers Are People TooProgrammers Are People Too

Eat Like HumansSleep Like HumansMate Like HumansThink Like Humans

Page 3: User Interface Principles in API Design

User Interface Design is a User Interface Design is a ScienceScienceBased on hypothesis, observation

and experimentWell-proven, well-tested theories

Page 4: User Interface Principles in API Design

Fundamental PrinciplesFundamental Principles

Consistency is next to godlinessSimpler is betterVisible complexity is badSmaller equals easier to use

Page 5: User Interface Principles in API Design

Libraries vs. ApplicationsLibraries vs. Applications

Applications are monolithicOnly other programmers on the

same team use an application’s APILibraries can make very limited

assumptions about how, when, where, and why API will be invoked

Boundary is fuzzy

Page 6: User Interface Principles in API Design

Remember the PeopleRemember the People

Why you need an APIWho uses the APIWho designs the API

Page 7: User Interface Principles in API Design

Be User FocusedBe User Focused

Ask what the user wants to do with your API

Do not ask what the internal data structures and algorithms look like

High level API is better than lower level--Reduce the number of method calls needed to accomplish the task

Design from the outside in

Page 8: User Interface Principles in API Design

What to put in an APIWhat to put in an API

Write sample programs first

80/20 rule

Maximal vs. Minimal APIs

YAGNI

When in doubt, leave it out!

Why I’m a conservative

Page 9: User Interface Principles in API Design

DependenciesDependencies

Platform versionLibrary dependenciesBuilt-in vs. 3rd party libraries

Page 10: User Interface Principles in API Design

Data EncapsulationData Encapsulation

Public vs. Published Fields are private Methods are mostly private Methods are atomic Constructors and destructors Communicating with the user

Page 11: User Interface Principles in API Design

ConstraintsConstraints

APIs must enforce domain validity

PreconditionsPostconditionsClass invariantsSystem invariants

Page 12: User Interface Principles in API Design

Error HandlingError Handling

Specify what happens on bad input as well as good

Important for securityNo undefined behaviorDon’t silently swallow exceptionsError messages should be verbose

but clearDon’t warn the user

Page 13: User Interface Principles in API Design

Naming ConventionsNaming Conventions

Review naming conventionsUse standard terminologyDo not abbreviateUse domain specific vocabularyConsistent terminology: always use

the same word for the same idea– e.g. add vs. append

Do not use two words for one idea

Page 14: User Interface Principles in API Design

Avoid ComplexityAvoid Complexity

Prefer classes to interfacesPrefer constructors to factory

methodsAvoid excessive abstractionYou usually don’t need multiple

implementationsRefactor to patterns; don’t start with

them. Avoid pattern overload!

Page 15: User Interface Principles in API Design

InheritanceInheritance

Prefer finality– (at least on methods)

Factories and interfacesThe proper use of protected

Page 16: User Interface Principles in API Design

Plays well with others (Java):Plays well with others (Java):

Serializable Cloneable(*) Comparable equals() hashCode() toString() Exception handling Thread safety

Page 17: User Interface Principles in API Design

Plays well with others (.NET):Plays well with others (.NET):

Equals() / GetHashCode() ToString() IEquatable<T> / IComparable<T> “Collection” suffix for IEnumerable classes Icloneable* Override ==, etc. for value types (only) No pointer arguments to public methods Don’t throw exceptions from overloaded

operators and implicit casts

Page 18: User Interface Principles in API Design

TestabilityTestability

The API itselfClient code that uses the APIThis is a secondary concern

Page 19: User Interface Principles in API Design

DocumentationDocumentation

SpecificationQuick StartTutorialsExample codeAPI DocumentationPer method checklist

Page 20: User Interface Principles in API Design

Conformance TestingConformance Testing

SpecificationsTest SuitesImplementation dependent behaviorImplementation dependent

extensions

Page 21: User Interface Principles in API Design

MaintenanceMaintenance

Planning for the futureForwards compatibilityBackwards compatibilityUnexpected limitsDeprecationBreaking compatibilityInterfaces vs. classes

Page 22: User Interface Principles in API Design

The Last Concern (Performance)The Last Concern (Performance)

SpeedSizeEnergy

Page 23: User Interface Principles in API Design

Case Study: JMidi vs. JFugueCase Study: JMidi vs. JFugue

Page 24: User Interface Principles in API Design

Case Study: DOM vs. JDOMCase Study: DOM vs. JDOM

Page 25: User Interface Principles in API Design

Case Study: BoxLayout vs. Case Study: BoxLayout vs. GridBagLayoutGridBagLayout

Page 26: User Interface Principles in API Design

Further ReadingFurther Reading

Effective Java: Joshua BlochEffective C#: Bill WagnerFramework Design Guidelines:

Krzysztof Cwalina, Brad AbramsTog on Interface: Bruce TognazziniGUI Bloopers: Jeff Johnson