SlideShare una empresa de Scribd logo
1 de 52
Writing usable APIs in
      practice
       SyncConf 2013


                 Giovanni Asproni
                 gasproni@asprotunity.com
                 @gasproni
Summary

• API definition
• Two assumptions
• Why bother with usability
• Some usability concepts
• Some techniques to improve usability
API

“Any well-defined interface that defines
the service that one component, module,
or application provides to other software
elements”




                               From: “Sometimes You Need to See Through Walls — A
                                  Field Study of Application Programming Interfaces”,
                              Cleidson R. B. de Souza et al., http://www.ufpa.br/cdesouza/
                                                 pub/p390-desouza.pdf
Package java.io
  Provides for system input and output through data streams, serialization and the file system.

  See: Description



   Interface Summary
   Interface                                                                                                                                                       Description
   Closeable                                                                                                                                                       A Closeable is a source or destination of data that can be closed.
   DataInput                                                                                                                                                       The DataInput interface provides for reading bytes from a binary stream and reconstructing from them data in any of the Java primitive types.
   DataOutput                                                                                                                                                      The DataOutput interface provides for converting data from any of the Java primitive types to a series of bytes and writing these bytes to a binary stream.
   Externalizable                                                                                                                                                  Only the identity of the class of an Externalizable instance is written in the serialization stream and it is the responsibility of the class to save and restore the contents of its instances.
   FileFilter                                                                                                                                                      A filter for abstract pathnames.
   FilenameFilter                                                                                                                                                  Instances of classes that implement this interface are used to filter filenames.
   Flushable                                                                                                                                                       A Flushable is a destination of data that can be flushed.
   ObjectInput                                                                                                                                                     ObjectInput extends the DataInput interface to include the reading of objects.
   ObjectInputValidation                                                                                                                                           Callback interface to allow validation of objects within a graph.
   ObjectOutput                                                                                                                                                    ObjectOutput extends the DataOutput interface to include writing of objects.
   ObjectStreamConstants                                                                                                                                           Constants written into the Object Serialization Stream.
   Serializable                                                                                                                                                    Serializability of a class is enabled by the class implementing the java.io.Serializable interface.



   Class Summary
   Class                                                                                                                                                           Description
   BufferedInputStream                                                                                                                                             A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the mark and reset methods.
   BufferedOutputStream                                                                                                                                            The class implements a buffered output stream.
   BufferedReader                                                                                                                                                  Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
   BufferedWriter                                                                                                                                                  Writes text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.
   ByteArrayInputStream                                                                                                                                            A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream.
   ByteArrayOutputStream                                                                                                                                           This class implements an output stream in which the data is written into a byte array.
   CharArrayReader                                                                                                                                                 This class implements a character buffer that can be used as a character-input stream.
   CharArrayWriter                                                                                                                                                 This class implements a character buffer that can be used as an Writer.
   Console                                                                                                                                                         Methods to access the character-based console device, if any, associated with the current Java virtual machine.
   DataInputStream                                                                                                                                                 A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way.
   DataOutputStream                                                                                                                                                A data output stream lets an application write primitive Java data types to an output stream in a portable way.
   File                                                                                                                                                            An abstract representation of file and directory pathnames.
   FileDescriptor                                                                                                                                                  Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes.
   FileInputStream                                                                                                                                                 A FileInputStream obtains input bytes from a file in a file system.
   FileOutputStream                                                                                                                                                A file output stream is an output stream for writing data to a File or to a FileDescriptor.
   FilePermission                                                                                                                                                  This class represents access to a file or directory.
   FileReader                                                                                                                                                      Convenience class for reading character files.
   FileWriter                                                                                                                                                      Convenience class for writing character files.
   FilterInputStream                                                                                                                                               A FilterInputStream contains some other input stream, which it uses as its basic source of data, possibly transforming the data along the way or providing additional functionality.
   FilterOutputStream                                                                                                                                              This class is the superclass of all classes that filter output streams.
   FilterReader                                                                                                                                                    Abstract class for reading filtered character streams.
   FilterWriter                                                                                                                                                    Abstract class for writing filtered character streams.
   InputStream                                                                                                                                                     This abstract class is the superclass of all classes representing an input stream of bytes.
   InputStreamReader                                                                                                                                               An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset.
   LineNumberInputStream                                                                                                                                           Deprecated
                                                                                                                                                                   This class incorrectly assumes that bytes adequately represent characters.
   LineNumberReader                                                                                                                                                A buffered character-input stream that keeps track of line numbers.
   ObjectInputStream                                                                                                                                               An ObjectInputStream deserializes primitive data and objects previously written using an ObjectOutputStream.
   ObjectInputStream.GetField                                                                                                                                      Provide access to the persistent fields read from the input stream.
   ObjectOutputStream                                                                                                                                              An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream.
   ObjectOutputStream.PutField                                                                                                                                     Provide programmatic access to the persistent fields to be written to ObjectOutput.
   ObjectStreamClass                                                                                                                                               Serialization's descriptor for classes.
   ObjectStreamField                                                                                                                                               A description of a Serializable field from a Serializable class.
   OutputStream                                                                                                                                                    This abstract class is the superclass of all classes representing an output stream of bytes.
   OutputStreamWriter                                                                                                                                              An OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specified charset.
   PipedInputStream                                                                                                                                                A piped input stream should be connected to a piped output stream; the piped input stream then provides whatever data bytes are written to the piped output stream.
   PipedOutputStream                                                                                                                                               A piped output stream can be connected to a piped input stream to create a communications pipe.
   PipedReader                                                                                                                                                     Piped character-input streams.
   PipedWriter                                                                                                                                                     Piped character-output streams.
   PrintStream                                                                                                                                                     A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently.
   PrintWriter                                                                                                                                                     Prints formatted representations of objects to a text-output stream.
   PushbackInputStream                                                                                                                                             A PushbackInputStream adds functionality to another input stream, namely the ability to "push back" or "unread" one byte.
   PushbackReader                                                                                                                                                  A character-stream reader that allows characters to be pushed back into the stream.
   RandomAccessFile                                                                                                                                                Instances of this class support both reading and writing to a random access file.
   Reader                                                                                                                                                          Abstract class for reading character streams.
   SequenceInputStream                                                                                                                                             A SequenceInputStream represents the logical concatenation of other input streams.
   SerializablePermission                                                                                                                                          This class is for Serializable permissions.
   StreamTokenizer                                                                                                                                                 The StreamTokenizer class takes an input stream and parses it into "tokens", allowing the tokens to be read one at a time.
   StringBufferInputStream                                                                                                                                         Deprecated
                                                                                                                                                                   This class does not properly convert characters into bytes.
   StringReader                                                                                                                                                    A character stream whose source is a string.
   StringWriter                                                                                                                                                    A character stream that collects its output in a string buffer, which can then be used to construct a string.
   Writer                                                                                                                                                          Abstract class for writing to character streams.



   Exception Summary
   Exception                                                                                                                                                       Description
   CharConversionException                                                                                                                                         Base class for character conversion exceptions.
   EOFException                                                                                                                                                    Signals that an end of file or end of stream has been reached unexpectedly during input.
   FileNotFoundException                                                                                                                                           Signals that an attempt to open the file denoted by a specified pathname has failed.
   InterruptedIOException                                                                                                                                          Signals that an I/O operation has been interrupted.
   InvalidClassException                                                                                                                                           Thrown when the Serialization runtime detects one of the following problems with a Class.
   InvalidObjectException                                                                                                                                          Indicates that one or more deserialized objects failed validation tests.
   IOException                                                                                                                                                     Signals that an I/O exception of some sort has occurred.
   NotActiveException                                                                                                                                              Thrown when serialization or deserialization is not active.
   NotSerializableException                                                                                                                                        Thrown when an instance is required to have a Serializable interface.
   ObjectStreamException                                                                                                                                           Superclass of all exceptions specific to Object Stream classes.
   OptionalDataException                                                                                                                                           Exception indicating the failure of an object read operation due to unread primitive data, or the end of data belonging to a serialized object in the stream.
   StreamCorruptedException                                                                                                                                        Thrown when control information that was read from an object stream violates internal consistency checks.
   SyncFailedException                                                                                                                                             Signals that a sync operation has failed.
   UnsupportedEncodingException                                                                                                                                    The Character Encoding is not supported.
   UTFDataFormatException                                                                                                                                          Signals that a malformed string in modified UTF-8 format has been read in a data input stream or by any class that implements the data input interface.
   WriteAbortedException                                                                                                                                           Signals that one of the ObjectStreamExceptions was thrown during a write operation.



   Error Summary
   Error                                                                                                                                                           Description
   IOError                                                                                                                                                         Thrown when a serious I/O error has occurred.



  Package java.io Description
  Provides for system input and output through data streams, serialization and the file system. Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.

  Package Specification
           Java Object Serialization Specification

  Related Documentation
  For overviews, tutorials, examples, guides, and tool documentation, please see:

           Serialization Enhancements

  Since:
           JDK1.0


                                                                                                                                                                                                                                                                                                                                                                      Java™ Platform
Overview     Package      Class   Use    Tree    Deprecated   Index   Help                                                                                                                                                                                                                                                                                            Standard Ed. 7


Prev Package      Next Package          Frames   No Frames        All Classes

Submit a bug or feature
Public and private APIs

• Public APIs
 • Given to third parties
• Private APIs
 • For internal use
First assumption

Any non trivial software application
involves writing one or more APIs
Second assumption

When we talk about good code
we always mean usable code as
well
Why bother (company’s
     perspective)

• APIs can be among a company's greatest
  assets
• Can also be among company's greatest
  liabilities


                              Adapted from: “How to Design a Good API and Why it
                              Matters”, Joshua Bloch, http://lcsd05.cs.tamu.edu/slides/
                                                   keynote.pdf
Why bother (programmer’s
      perspective)

• Fewer bugs to take care of
• Code of higher quality
• More productivity
Affordances

An affordance is a quality of an object, or
an environment, that allows an individual
to perform an action.




                                  From: http://en.wikipedia.org/wiki/Affordance
Affordances: processing file
      line by line (Java 6)
BufferedReader reader;
try {
    reader = new BufferedReader(new FileReader(“filename“));
    while (true) {
        String line = reader.readLine();
        if (line == null) {
            break;
        }
        processLine(line);
    }
}
catch (Exception exc) {
    // Do something here...
}
finally {
    if (reader != null) {
        reader.close();
    }
}
Affordances that are easier
              to see (Java 7)

try {
    Path filePath = FileSystems.getDefault().getPath("filename");
    Charset charset = Charset.defaultCharset();
    for (String line : Files.readAllLines(filePath, charset)) {
         processLine(line);
    }
} catch (IOException e) {
    // Do something here
}
And even easier (Python 3)


 with open("filename") as infile:
      for line in infile.readlines():
               processLine(line)
Some cognitive dimensions
•   Abstraction level. The minimum and maximum levels of
    abstraction exposed by the API
•   Working framework. The size of the conceptual chunk
    (developer working set) needed to work effectively
•   Progressive evaluation. To what extent partially
    completed code can be executed to obtain feedback on
    code behaviour
•   Penetrability. How the API facilitates exploration,
    analysis, and understanding of its components
•   Consistency. How much of the rest of an API can be
    inferred once part of it is learned
                                            Adapted from: “Measuring API Usability”, Steven Clarke,
                                                  http://drdobbs.com/windows/184405654
BufferedReader reader;
try {
    reader = new BufferedReader(new FileReader(“filename“));
    while (true) {
        String line = reader.readLine();
        if (line == null) {
            break;
        }
        processLine(line);
    }
}                                             •   Abstraction
catch (Exception exc) {                           level.
    // Do something here...
}                                             •   Working
                                                  framework.
finally {
    if (reader != null) {                     •   Progressive
        reader.close();                           evaluation.
    }
}                                             •   Penetrability.
                                              •   Consistency.
try {
    Path filePath = FileSystems.getDefault().getPath("filename");
    Charset charset = Charset.defaultCharset();
    for (String line : Files.readAllLines(filePath, charset)) {
        processLine(line);
    }
} catch (IOException e) {                           •   Abstraction
                                                        level.
    // Do something here
}                                                   •   Working
                                                        framework.
                                                    •   Progressive
                                                        evaluation.
                                                    •   Penetrability.
                                                    •   Consistency.
with open("filename") as infile:
    for line in infile.readlines():
        processLine(line)

                                 •    Abstraction
                                      level.
                                 •    Working
                                      framework.
                                 •    Progressive
                                      evaluation.
                                 •    Penetrability.
                                 •    Consistency.
“Make Interfaces Easy to Use Correctly
and Hard to Use Incorrectly”

            Scott Meyers, “97 Things Every
              Programmer Should Know”
Some techniques
•   User’s perspective
•   Naming
•   Give control to the caller
•   Explicit context
•   Error reporting
•   Logging as a feature
•   Incremental design
•   User’s perspective
•   Naming
•   Give control to the caller
•   Explicit context
•   Error reporting
•   Logging as a feature
•   Incremental design
“Ask, ‘What Would the User
Do?’ (You Are Not the User)”

     Giles Colborne, “97 Things
     Every Programmer Should
                        Know”
Golden Rule of API Design

“It’s not enough to write tests for an API you develop; you
have to write unit tests for code that uses your API. When
you follow this rule, you learn firsthand the hurdles that
your users will have to overcome when they try to test
their code independently.”


  Michael Feathers, “97 Things Every Programmer Should
                                                Know”
TDD

• It puts you in the shoes of an user
 • If writing a test is painful, the design may
    be wrong
• Tests will provide up to date
  documentation and examples of use
TDD helps with
•   Abstraction level. It helps to limit the number
    of abstractions in mainline scenarios
•   Working framework
•   Progressive evaluation
•   Penetrability. It provides examples on how the
    various components interact with each other
•   Consistency. It is maintained by refactoring
    the code
                                     Adapted from: “Measuring API Usability”, Steven Clarke,
                                           http://drdobbs.com/windows/184405654
File file = new File(“filename“));
try {
    for (String line : file.readLines()) {
        processLine(line);
    }
}
finally {
    file.close()
}
BufferedReader reader;
try {
    reader = new BufferedReader(new FileReader(“filename“));
    while (true) {
        String line = reader.readLine();
        if (line == null) {
            break;
        }
        processLine(line);
    }
}
catch (Exception exc) {
    // Do something here...
}
finally {
    if (reader != null) {
        reader.close();
    }
}
•   User’s perspective
•   Naming
•   Give control to the caller
•   Explicit context
•   Error reporting
•   Logging as a feature
•   Incremental design
• Reserve the simplest and most intuitive
  names names for the entities used in the
  most common scenarios
• Pick one word per concept
• Don’t be cute!
•   User’s perspective
•   Naming
•   Give control to the caller
•   Explicit context
•   Error reporting
•   Logging as a feature
•   Incremental design
What’s wrong with these?
public interface Startable {
    Startable start()
        throws AlreadyStartedException;
}

public interface Stoppable {
    Stoppable stop()
        throws AlreadyStoppedException;
}
A better alternative
public interface Service {
    void start()
        throws AlreadyStartedException;

    void stop()
        throws AlreadyStoppedException;

    boolean isStarted();
}
•   User’s perspective
•   Naming
•   Give control to the caller
•   Explicit context
•   Error reporting
•   Logging as a feature
•   Incremental design
Explicit context

• Assumptions about the external
  environment
• There are two kinds of context we are
  interested in
 • Deployment context
 • Runtime context
Deployment context

• Dependencies on other APIs
• Assumptions on deployment paths
• User permissions
• etc.
Runtime context

• Preconditions for calling methods (or
  functions) or instantiating classes
• Initialisation (and finalisation) steps
• etc.
Global state

• Difficult to use in a concurrent
  environment
• Can make test setup extremely hard
• Can make functionality difficult to use by
  hiding dependencies
•   User’s perspective
•   Naming
•   Give control to the caller
•   Explicit context
•   Error reporting
•   Logging as a feature
•   Incremental design
Error reporting
• Error reporting code is important for
  usability
• Users need to know
 • How errors are reported
 • What is reported when
 • What they can do about them
Error recovery

• Make recovery easy to do
 • Error codes
 • Exception classes
 • A mix of the above
• Text messages are usually not good enough
What is an error at one
        level....

...May not be an error at another one
•   User’s perspective
•   Naming
•   Give control to the caller
•   Explicit context
•   Error reporting
•   Logging as a feature
•   Incremental design
Two types of logging
• Support logging (errors and info) is
  part of the user interface of the
  application. These messages are intended to
  be tracked by support staff and operators
  to monitor the running system
• Diagnostic logging (debug and trace) is
  infrastructure for programmers. Not for
  production
                               Adapted from: “Growing Object Oriented Code Driven by
                                 Tests”, Steve Freeman and Nat Pryce, Addison Wesley
Location location = tracker.getCurrentLocation();

for (Filter filter : filters) {

    filter.selectFor(location);

    if (logger.isInfoEnabled()) {
        logger.info("Filter "
        + filter.getName()
        + ", "
        + filter.getDate()
        + " selected for " + location.getName()
        + ", is current: " + tracker.isCurrent(location));
    }
}


                                       From: “Growing Object Oriented Code Driven by Tests”,
                                           Steve Freeman and Nat Pryce, Addison Wesley
Location location = tracker.getCurrentLocation();
for (Filter filter : filters) {
    filter.selectFor(location);
    support.notifyFiltering(tracker, location, filter);
}




                                    From: “Growing Object Oriented Code Driven by Tests”,
                                        Steve Freeman and Nat Pryce, Addison Wesley
Give the programmer a
          choice

• It should be possible to turn logging on and
  off
• When on, give programmers a chance to
  use logging on their own terms
•   User’s perspective
•   Naming
•   Give control to the caller
•   Explicit context
•   Error reporting
•   Logging as a feature
•   Incremental design
Conceptual integrity
I will contend that conceptual integrity
is the most important consideration in
system design. It is better to have a
system omit certain anomalous
features and improvements, but to
reflect one set of design ideas, than to
have one that contains many good but
independent and uncoordinated ideas.

                                 Fred Brooks, “The Mythical Man Month”
Start specific and small

• Start with the 80% case first
• It is easier to remove constraints rather
  than to add them later
• YAGNI
A caveat

• Public APIs are more difficult to refactor. In
  fact, some errors may actually become
  features
• Techniques to refactor them usually involve
  some form of deprecation and versioning
•   User’s perspective
•   Naming
•   Give control to the caller
•   Explicit context
•   Error reporting
•   Logging as a feature
•   Incremental design
Links
•   http://www.apiusability.org
•   “Sometimes You Need to See Through Walls — A Field Study of Application
    Programming Interfaces”, Cleidson R. B. de Souza et al., http://www.ufpa.br/
    cdesouza/pub/p390-desouza.pdf
•   “Measuring API Usability”, Steven Clarke, http://drdobbs.com/windows/
    184405654
•   http://en.wikipedia.org/wiki/Affordance
•   “How to Design a Good API and Why it Matters”, Joshua Bloch, http://
    lcsd05.cs.tamu.edu/slides/keynote.pdf
•   “What Makes APIs Difficult to Use?”, Minhaz Fahim Zibran, http://
    paper.ijcsns.org/07_book/200804/20080436.pdf
•   http://www.codeproject.com/Articles/8707/API-Usability-Guidelines-to-
    improve-your-code-ease
Books



                                       ptg6931361




From the Library of Giovanni Asproni

Más contenido relacionado

La actualidad más candente

Sfmodelsecondpartrefcard
SfmodelsecondpartrefcardSfmodelsecondpartrefcard
SfmodelsecondpartrefcardMaksim Kotlyar
 
Xml representation oftextspecifications
Xml representation oftextspecificationsXml representation oftextspecifications
Xml representation oftextspecificationsusert098
 
Introduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging APIIntroduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging APIwhite paper
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat SheetGlowTouch
 
02 Hibernate Introduction
02 Hibernate Introduction02 Hibernate Introduction
02 Hibernate IntroductionRanjan Kumar
 
9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlin9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlinZoran Stanimirovic
 
Java session02
Java session02Java session02
Java session02Niit Care
 
Java Programming Guide Quick Reference
Java Programming Guide Quick ReferenceJava Programming Guide Quick Reference
Java Programming Guide Quick ReferenceFrescatiStory
 
EJB 3.0 Walkthrough (2006)
EJB 3.0 Walkthrough (2006)EJB 3.0 Walkthrough (2006)
EJB 3.0 Walkthrough (2006)Peter Antman
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 

La actualidad más candente (16)

Sfmodelsecondpartrefcard
SfmodelsecondpartrefcardSfmodelsecondpartrefcard
Sfmodelsecondpartrefcard
 
Cheat Sheet java
Cheat Sheet javaCheat Sheet java
Cheat Sheet java
 
Pocket java
Pocket javaPocket java
Pocket java
 
Xml representation oftextspecifications
Xml representation oftextspecificationsXml representation oftextspecifications
Xml representation oftextspecifications
 
JAVA BASICS
JAVA BASICSJAVA BASICS
JAVA BASICS
 
Introduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging APIIntroduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging API
 
iOS Application Development
iOS Application DevelopmentiOS Application Development
iOS Application Development
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
02 Hibernate Introduction
02 Hibernate Introduction02 Hibernate Introduction
02 Hibernate Introduction
 
9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlin9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlin
 
Gdb cheat sheet
Gdb cheat sheetGdb cheat sheet
Gdb cheat sheet
 
Java session02
Java session02Java session02
Java session02
 
Java Annotations
Java AnnotationsJava Annotations
Java Annotations
 
Java Programming Guide Quick Reference
Java Programming Guide Quick ReferenceJava Programming Guide Quick Reference
Java Programming Guide Quick Reference
 
EJB 3.0 Walkthrough (2006)
EJB 3.0 Walkthrough (2006)EJB 3.0 Walkthrough (2006)
EJB 3.0 Walkthrough (2006)
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 

Destacado

Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Robin O'Brien
 
DevTeach12-betterspecs
DevTeach12-betterspecsDevTeach12-betterspecs
DevTeach12-betterspecsAmir Barylko
 
Behavior-Driven Development (BDD) in context
Behavior-Driven Development (BDD) in contextBehavior-Driven Development (BDD) in context
Behavior-Driven Development (BDD) in contextAlexander Kress
 
.NET executable requirements
.NET executable requirements.NET executable requirements
.NET executable requirementsGodfrey Nolan
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkinArati Joshi
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by ExampleNalin Goonawardana
 
Tableau 10 and quickbooks
Tableau 10 and quickbooksTableau 10 and quickbooks
Tableau 10 and quickbooksGodfrey Nolan
 
A Guide to Modern BPM Data Integration
A Guide to Modern BPM Data IntegrationA Guide to Modern BPM Data Integration
A Guide to Modern BPM Data IntegrationEric D. Schabell
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumberDaniel Kummer
 
Story Driven Development With Cucumber
Story Driven Development With CucumberStory Driven Development With Cucumber
Story Driven Development With CucumberSean Cribbs
 
BDD presentation
BDD presentationBDD presentation
BDD presentationtemebele
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Lars Thorup
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web developmentAmir Barylko
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testingdversaci
 

Destacado (20)

Born Digital - Dan Franklin
Born Digital - Dan FranklinBorn Digital - Dan Franklin
Born Digital - Dan Franklin
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Cucumber_Training_ForQA
Cucumber_Training_ForQACucumber_Training_ForQA
Cucumber_Training_ForQA
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development
 
DevTeach12-betterspecs
DevTeach12-betterspecsDevTeach12-betterspecs
DevTeach12-betterspecs
 
Behavior-Driven Development (BDD) in context
Behavior-Driven Development (BDD) in contextBehavior-Driven Development (BDD) in context
Behavior-Driven Development (BDD) in context
 
.NET executable requirements
.NET executable requirements.NET executable requirements
.NET executable requirements
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkin
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
 
Tableau 10 and quickbooks
Tableau 10 and quickbooksTableau 10 and quickbooks
Tableau 10 and quickbooks
 
A Guide to Modern BPM Data Integration
A Guide to Modern BPM Data IntegrationA Guide to Modern BPM Data Integration
A Guide to Modern BPM Data Integration
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
Story Driven Development With Cucumber
Story Driven Development With CucumberStory Driven Development With Cucumber
Story Driven Development With Cucumber
 
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
 
Feature Writing
Feature WritingFeature Writing
Feature Writing
 
BDD presentation
BDD presentationBDD presentation
BDD presentation
 
Cucumber ppt
Cucumber pptCucumber ppt
Cucumber ppt
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web development
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testing
 

Similar a Writing Usable APIs in Practice by Giovanni Asproni

inputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfinputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfhemanth248901
 
Java I/O and Object Serialization
Java I/O and Object SerializationJava I/O and Object Serialization
Java I/O and Object SerializationNavneet Prakash
 
CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxSadhilAggarwal
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scannerArif Ullah
 
IO and serialization
IO and serializationIO and serialization
IO and serializationbackdoor
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Akshay Nagpurkar
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Akshay Nagpurkar
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output ConceptsVicter Paul
 
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Outputphanleson
 
Answer ado.net pre-exam2018
Answer ado.net pre-exam2018Answer ado.net pre-exam2018
Answer ado.net pre-exam2018than sare
 
Java programming Chapter 4.pptx
Java programming Chapter 4.pptxJava programming Chapter 4.pptx
Java programming Chapter 4.pptxssusera0d3d2
 
L21 io streams
L21 io streamsL21 io streams
L21 io streamsteach4uin
 

Similar a Writing Usable APIs in Practice by Giovanni Asproni (20)

Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 
Input output streams
Input output streamsInput output streams
Input output streams
 
inputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfinputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdf
 
Input & output
Input & outputInput & output
Input & output
 
Java I/O and Object Serialization
Java I/O and Object SerializationJava I/O and Object Serialization
Java I/O and Object Serialization
 
CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptx
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
 
IO and serialization
IO and serializationIO and serialization
IO and serialization
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
 
Java quickref
Java quickrefJava quickref
Java quickref
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
 
Io stream
Io streamIo stream
Io stream
 
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
 
Answer ado.net pre-exam2018
Answer ado.net pre-exam2018Answer ado.net pre-exam2018
Answer ado.net pre-exam2018
 
Java_Interview Qns
Java_Interview QnsJava_Interview Qns
Java_Interview Qns
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
Java programming Chapter 4.pptx
Java programming Chapter 4.pptxJava programming Chapter 4.pptx
Java programming Chapter 4.pptx
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 

Más de SyncConf

The Multimap Journey and How to raise Angel Investment by Sean Phelan
The Multimap Journey and How to raise Angel Investment by Sean PhelanThe Multimap Journey and How to raise Angel Investment by Sean Phelan
The Multimap Journey and How to raise Angel Investment by Sean PhelanSyncConf
 
Behaviour Driven Development by Liz Keogh
Behaviour Driven Development by Liz KeoghBehaviour Driven Development by Liz Keogh
Behaviour Driven Development by Liz KeoghSyncConf
 
Tackling Complex Data with Neo4j by Ian Robinson
Tackling Complex Data with Neo4j by Ian RobinsonTackling Complex Data with Neo4j by Ian Robinson
Tackling Complex Data with Neo4j by Ian RobinsonSyncConf
 
Next Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerNext Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerSyncConf
 
The Ubiquitous Digital Map (Abridged) by Gary Gale
The Ubiquitous Digital Map (Abridged) by Gary GaleThe Ubiquitous Digital Map (Abridged) by Gary Gale
The Ubiquitous Digital Map (Abridged) by Gary GaleSyncConf
 
Breaking News and Breaking Software by Andy Hume
Breaking News and Breaking Software by Andy HumeBreaking News and Breaking Software by Andy Hume
Breaking News and Breaking Software by Andy HumeSyncConf
 
The 90 minute Guide to Agile – What, Why, How by Allan Kelly
The 90 minute Guide to Agile – What, Why, How by Allan KellyThe 90 minute Guide to Agile – What, Why, How by Allan Kelly
The 90 minute Guide to Agile – What, Why, How by Allan KellySyncConf
 

Más de SyncConf (7)

The Multimap Journey and How to raise Angel Investment by Sean Phelan
The Multimap Journey and How to raise Angel Investment by Sean PhelanThe Multimap Journey and How to raise Angel Investment by Sean Phelan
The Multimap Journey and How to raise Angel Investment by Sean Phelan
 
Behaviour Driven Development by Liz Keogh
Behaviour Driven Development by Liz KeoghBehaviour Driven Development by Liz Keogh
Behaviour Driven Development by Liz Keogh
 
Tackling Complex Data with Neo4j by Ian Robinson
Tackling Complex Data with Neo4j by Ian RobinsonTackling Complex Data with Neo4j by Ian Robinson
Tackling Complex Data with Neo4j by Ian Robinson
 
Next Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerNext Top Data Model by Ian Plosker
Next Top Data Model by Ian Plosker
 
The Ubiquitous Digital Map (Abridged) by Gary Gale
The Ubiquitous Digital Map (Abridged) by Gary GaleThe Ubiquitous Digital Map (Abridged) by Gary Gale
The Ubiquitous Digital Map (Abridged) by Gary Gale
 
Breaking News and Breaking Software by Andy Hume
Breaking News and Breaking Software by Andy HumeBreaking News and Breaking Software by Andy Hume
Breaking News and Breaking Software by Andy Hume
 
The 90 minute Guide to Agile – What, Why, How by Allan Kelly
The 90 minute Guide to Agile – What, Why, How by Allan KellyThe 90 minute Guide to Agile – What, Why, How by Allan Kelly
The 90 minute Guide to Agile – What, Why, How by Allan Kelly
 

Último

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Writing Usable APIs in Practice by Giovanni Asproni

  • 1. Writing usable APIs in practice SyncConf 2013 Giovanni Asproni gasproni@asprotunity.com @gasproni
  • 2. Summary • API definition • Two assumptions • Why bother with usability • Some usability concepts • Some techniques to improve usability
  • 3. API “Any well-defined interface that defines the service that one component, module, or application provides to other software elements” From: “Sometimes You Need to See Through Walls — A Field Study of Application Programming Interfaces”, Cleidson R. B. de Souza et al., http://www.ufpa.br/cdesouza/ pub/p390-desouza.pdf
  • 4. Package java.io Provides for system input and output through data streams, serialization and the file system. See: Description Interface Summary Interface Description Closeable A Closeable is a source or destination of data that can be closed. DataInput The DataInput interface provides for reading bytes from a binary stream and reconstructing from them data in any of the Java primitive types. DataOutput The DataOutput interface provides for converting data from any of the Java primitive types to a series of bytes and writing these bytes to a binary stream. Externalizable Only the identity of the class of an Externalizable instance is written in the serialization stream and it is the responsibility of the class to save and restore the contents of its instances. FileFilter A filter for abstract pathnames. FilenameFilter Instances of classes that implement this interface are used to filter filenames. Flushable A Flushable is a destination of data that can be flushed. ObjectInput ObjectInput extends the DataInput interface to include the reading of objects. ObjectInputValidation Callback interface to allow validation of objects within a graph. ObjectOutput ObjectOutput extends the DataOutput interface to include writing of objects. ObjectStreamConstants Constants written into the Object Serialization Stream. Serializable Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Class Summary Class Description BufferedInputStream A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the mark and reset methods. BufferedOutputStream The class implements a buffered output stream. BufferedReader Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. BufferedWriter Writes text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings. ByteArrayInputStream A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream. ByteArrayOutputStream This class implements an output stream in which the data is written into a byte array. CharArrayReader This class implements a character buffer that can be used as a character-input stream. CharArrayWriter This class implements a character buffer that can be used as an Writer. Console Methods to access the character-based console device, if any, associated with the current Java virtual machine. DataInputStream A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way. DataOutputStream A data output stream lets an application write primitive Java data types to an output stream in a portable way. File An abstract representation of file and directory pathnames. FileDescriptor Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes. FileInputStream A FileInputStream obtains input bytes from a file in a file system. FileOutputStream A file output stream is an output stream for writing data to a File or to a FileDescriptor. FilePermission This class represents access to a file or directory. FileReader Convenience class for reading character files. FileWriter Convenience class for writing character files. FilterInputStream A FilterInputStream contains some other input stream, which it uses as its basic source of data, possibly transforming the data along the way or providing additional functionality. FilterOutputStream This class is the superclass of all classes that filter output streams. FilterReader Abstract class for reading filtered character streams. FilterWriter Abstract class for writing filtered character streams. InputStream This abstract class is the superclass of all classes representing an input stream of bytes. InputStreamReader An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. LineNumberInputStream Deprecated This class incorrectly assumes that bytes adequately represent characters. LineNumberReader A buffered character-input stream that keeps track of line numbers. ObjectInputStream An ObjectInputStream deserializes primitive data and objects previously written using an ObjectOutputStream. ObjectInputStream.GetField Provide access to the persistent fields read from the input stream. ObjectOutputStream An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream. ObjectOutputStream.PutField Provide programmatic access to the persistent fields to be written to ObjectOutput. ObjectStreamClass Serialization's descriptor for classes. ObjectStreamField A description of a Serializable field from a Serializable class. OutputStream This abstract class is the superclass of all classes representing an output stream of bytes. OutputStreamWriter An OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specified charset. PipedInputStream A piped input stream should be connected to a piped output stream; the piped input stream then provides whatever data bytes are written to the piped output stream. PipedOutputStream A piped output stream can be connected to a piped input stream to create a communications pipe. PipedReader Piped character-input streams. PipedWriter Piped character-output streams. PrintStream A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently. PrintWriter Prints formatted representations of objects to a text-output stream. PushbackInputStream A PushbackInputStream adds functionality to another input stream, namely the ability to "push back" or "unread" one byte. PushbackReader A character-stream reader that allows characters to be pushed back into the stream. RandomAccessFile Instances of this class support both reading and writing to a random access file. Reader Abstract class for reading character streams. SequenceInputStream A SequenceInputStream represents the logical concatenation of other input streams. SerializablePermission This class is for Serializable permissions. StreamTokenizer The StreamTokenizer class takes an input stream and parses it into "tokens", allowing the tokens to be read one at a time. StringBufferInputStream Deprecated This class does not properly convert characters into bytes. StringReader A character stream whose source is a string. StringWriter A character stream that collects its output in a string buffer, which can then be used to construct a string. Writer Abstract class for writing to character streams. Exception Summary Exception Description CharConversionException Base class for character conversion exceptions. EOFException Signals that an end of file or end of stream has been reached unexpectedly during input. FileNotFoundException Signals that an attempt to open the file denoted by a specified pathname has failed. InterruptedIOException Signals that an I/O operation has been interrupted. InvalidClassException Thrown when the Serialization runtime detects one of the following problems with a Class. InvalidObjectException Indicates that one or more deserialized objects failed validation tests. IOException Signals that an I/O exception of some sort has occurred. NotActiveException Thrown when serialization or deserialization is not active. NotSerializableException Thrown when an instance is required to have a Serializable interface. ObjectStreamException Superclass of all exceptions specific to Object Stream classes. OptionalDataException Exception indicating the failure of an object read operation due to unread primitive data, or the end of data belonging to a serialized object in the stream. StreamCorruptedException Thrown when control information that was read from an object stream violates internal consistency checks. SyncFailedException Signals that a sync operation has failed. UnsupportedEncodingException The Character Encoding is not supported. UTFDataFormatException Signals that a malformed string in modified UTF-8 format has been read in a data input stream or by any class that implements the data input interface. WriteAbortedException Signals that one of the ObjectStreamExceptions was thrown during a write operation. Error Summary Error Description IOError Thrown when a serious I/O error has occurred. Package java.io Description Provides for system input and output through data streams, serialization and the file system. Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown. Package Specification Java Object Serialization Specification Related Documentation For overviews, tutorials, examples, guides, and tool documentation, please see: Serialization Enhancements Since: JDK1.0 Java™ Platform Overview Package Class Use Tree Deprecated Index Help Standard Ed. 7 Prev Package Next Package Frames No Frames All Classes Submit a bug or feature
  • 5. Public and private APIs • Public APIs • Given to third parties • Private APIs • For internal use
  • 6. First assumption Any non trivial software application involves writing one or more APIs
  • 7. Second assumption When we talk about good code we always mean usable code as well
  • 8. Why bother (company’s perspective) • APIs can be among a company's greatest assets • Can also be among company's greatest liabilities Adapted from: “How to Design a Good API and Why it Matters”, Joshua Bloch, http://lcsd05.cs.tamu.edu/slides/ keynote.pdf
  • 9. Why bother (programmer’s perspective) • Fewer bugs to take care of • Code of higher quality • More productivity
  • 10. Affordances An affordance is a quality of an object, or an environment, that allows an individual to perform an action. From: http://en.wikipedia.org/wiki/Affordance
  • 11. Affordances: processing file line by line (Java 6) BufferedReader reader; try { reader = new BufferedReader(new FileReader(“filename“)); while (true) { String line = reader.readLine(); if (line == null) { break; } processLine(line); } } catch (Exception exc) { // Do something here... } finally { if (reader != null) { reader.close(); } }
  • 12. Affordances that are easier to see (Java 7) try { Path filePath = FileSystems.getDefault().getPath("filename"); Charset charset = Charset.defaultCharset(); for (String line : Files.readAllLines(filePath, charset)) { processLine(line); } } catch (IOException e) { // Do something here }
  • 13. And even easier (Python 3) with open("filename") as infile: for line in infile.readlines(): processLine(line)
  • 14. Some cognitive dimensions • Abstraction level. The minimum and maximum levels of abstraction exposed by the API • Working framework. The size of the conceptual chunk (developer working set) needed to work effectively • Progressive evaluation. To what extent partially completed code can be executed to obtain feedback on code behaviour • Penetrability. How the API facilitates exploration, analysis, and understanding of its components • Consistency. How much of the rest of an API can be inferred once part of it is learned Adapted from: “Measuring API Usability”, Steven Clarke, http://drdobbs.com/windows/184405654
  • 15. BufferedReader reader; try { reader = new BufferedReader(new FileReader(“filename“)); while (true) { String line = reader.readLine(); if (line == null) { break; } processLine(line); } } • Abstraction catch (Exception exc) { level. // Do something here... } • Working framework. finally { if (reader != null) { • Progressive reader.close(); evaluation. } } • Penetrability. • Consistency.
  • 16. try { Path filePath = FileSystems.getDefault().getPath("filename"); Charset charset = Charset.defaultCharset(); for (String line : Files.readAllLines(filePath, charset)) { processLine(line); } } catch (IOException e) { • Abstraction level. // Do something here } • Working framework. • Progressive evaluation. • Penetrability. • Consistency.
  • 17. with open("filename") as infile: for line in infile.readlines(): processLine(line) • Abstraction level. • Working framework. • Progressive evaluation. • Penetrability. • Consistency.
  • 18. “Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly” Scott Meyers, “97 Things Every Programmer Should Know”
  • 19. Some techniques • User’s perspective • Naming • Give control to the caller • Explicit context • Error reporting • Logging as a feature • Incremental design
  • 20. User’s perspective • Naming • Give control to the caller • Explicit context • Error reporting • Logging as a feature • Incremental design
  • 21. “Ask, ‘What Would the User Do?’ (You Are Not the User)” Giles Colborne, “97 Things Every Programmer Should Know”
  • 22. Golden Rule of API Design “It’s not enough to write tests for an API you develop; you have to write unit tests for code that uses your API. When you follow this rule, you learn firsthand the hurdles that your users will have to overcome when they try to test their code independently.” Michael Feathers, “97 Things Every Programmer Should Know”
  • 23. TDD • It puts you in the shoes of an user • If writing a test is painful, the design may be wrong • Tests will provide up to date documentation and examples of use
  • 24. TDD helps with • Abstraction level. It helps to limit the number of abstractions in mainline scenarios • Working framework • Progressive evaluation • Penetrability. It provides examples on how the various components interact with each other • Consistency. It is maintained by refactoring the code Adapted from: “Measuring API Usability”, Steven Clarke, http://drdobbs.com/windows/184405654
  • 25. File file = new File(“filename“)); try { for (String line : file.readLines()) { processLine(line); } } finally { file.close() }
  • 26. BufferedReader reader; try { reader = new BufferedReader(new FileReader(“filename“)); while (true) { String line = reader.readLine(); if (line == null) { break; } processLine(line); } } catch (Exception exc) { // Do something here... } finally { if (reader != null) { reader.close(); } }
  • 27. User’s perspective • Naming • Give control to the caller • Explicit context • Error reporting • Logging as a feature • Incremental design
  • 28. • Reserve the simplest and most intuitive names names for the entities used in the most common scenarios • Pick one word per concept • Don’t be cute!
  • 29. User’s perspective • Naming • Give control to the caller • Explicit context • Error reporting • Logging as a feature • Incremental design
  • 30. What’s wrong with these? public interface Startable { Startable start() throws AlreadyStartedException; } public interface Stoppable { Stoppable stop() throws AlreadyStoppedException; }
  • 31. A better alternative public interface Service { void start() throws AlreadyStartedException; void stop() throws AlreadyStoppedException; boolean isStarted(); }
  • 32. User’s perspective • Naming • Give control to the caller • Explicit context • Error reporting • Logging as a feature • Incremental design
  • 33. Explicit context • Assumptions about the external environment • There are two kinds of context we are interested in • Deployment context • Runtime context
  • 34. Deployment context • Dependencies on other APIs • Assumptions on deployment paths • User permissions • etc.
  • 35. Runtime context • Preconditions for calling methods (or functions) or instantiating classes • Initialisation (and finalisation) steps • etc.
  • 36. Global state • Difficult to use in a concurrent environment • Can make test setup extremely hard • Can make functionality difficult to use by hiding dependencies
  • 37. User’s perspective • Naming • Give control to the caller • Explicit context • Error reporting • Logging as a feature • Incremental design
  • 38. Error reporting • Error reporting code is important for usability • Users need to know • How errors are reported • What is reported when • What they can do about them
  • 39. Error recovery • Make recovery easy to do • Error codes • Exception classes • A mix of the above • Text messages are usually not good enough
  • 40. What is an error at one level.... ...May not be an error at another one
  • 41. User’s perspective • Naming • Give control to the caller • Explicit context • Error reporting • Logging as a feature • Incremental design
  • 42. Two types of logging • Support logging (errors and info) is part of the user interface of the application. These messages are intended to be tracked by support staff and operators to monitor the running system • Diagnostic logging (debug and trace) is infrastructure for programmers. Not for production Adapted from: “Growing Object Oriented Code Driven by Tests”, Steve Freeman and Nat Pryce, Addison Wesley
  • 43. Location location = tracker.getCurrentLocation(); for (Filter filter : filters) { filter.selectFor(location); if (logger.isInfoEnabled()) { logger.info("Filter " + filter.getName() + ", " + filter.getDate() + " selected for " + location.getName() + ", is current: " + tracker.isCurrent(location)); } } From: “Growing Object Oriented Code Driven by Tests”, Steve Freeman and Nat Pryce, Addison Wesley
  • 44. Location location = tracker.getCurrentLocation(); for (Filter filter : filters) { filter.selectFor(location); support.notifyFiltering(tracker, location, filter); } From: “Growing Object Oriented Code Driven by Tests”, Steve Freeman and Nat Pryce, Addison Wesley
  • 45. Give the programmer a choice • It should be possible to turn logging on and off • When on, give programmers a chance to use logging on their own terms
  • 46. User’s perspective • Naming • Give control to the caller • Explicit context • Error reporting • Logging as a feature • Incremental design
  • 47. Conceptual integrity I will contend that conceptual integrity is the most important consideration in system design. It is better to have a system omit certain anomalous features and improvements, but to reflect one set of design ideas, than to have one that contains many good but independent and uncoordinated ideas. Fred Brooks, “The Mythical Man Month”
  • 48. Start specific and small • Start with the 80% case first • It is easier to remove constraints rather than to add them later • YAGNI
  • 49. A caveat • Public APIs are more difficult to refactor. In fact, some errors may actually become features • Techniques to refactor them usually involve some form of deprecation and versioning
  • 50. User’s perspective • Naming • Give control to the caller • Explicit context • Error reporting • Logging as a feature • Incremental design
  • 51. Links • http://www.apiusability.org • “Sometimes You Need to See Through Walls — A Field Study of Application Programming Interfaces”, Cleidson R. B. de Souza et al., http://www.ufpa.br/ cdesouza/pub/p390-desouza.pdf • “Measuring API Usability”, Steven Clarke, http://drdobbs.com/windows/ 184405654 • http://en.wikipedia.org/wiki/Affordance • “How to Design a Good API and Why it Matters”, Joshua Bloch, http:// lcsd05.cs.tamu.edu/slides/keynote.pdf • “What Makes APIs Difficult to Use?”, Minhaz Fahim Zibran, http:// paper.ijcsns.org/07_book/200804/20080436.pdf • http://www.codeproject.com/Articles/8707/API-Usability-Guidelines-to- improve-your-code-ease
  • 52. Books ptg6931361 From the Library of Giovanni Asproni