Usability Implications of Requiring Parameters in Objects' - - PowerPoint PPT Presentation

usability implications of requiring parameters in objects
SMART_READER_LITE
LIVE PREVIEW

Usability Implications of Requiring Parameters in Objects' - - PowerPoint PPT Presentation

Usability Implications of Requiring Parameters in Objects' Constructors written by Jeffrey Stylos and Steven Clarke published at ICSE 2007 talk by Dino Wernli Intent of Paper Inspect influence of constructors on API usability Default


slide-1
SLIDE 1

Usability Implications of Requiring Parameters in Objects' Constructors

written by Jeffrey Stylos and Steven Clarke published at ICSE 2007 talk by Dino Wernli

slide-2
SLIDE 2

2

Intent of Paper

 Inspect influence of constructors on API usability

 Default constructor vs. required constructor

 Perform study to analyze programmers at work  Draw conclusions for future API design

slide-3
SLIDE 3

3

Default Constructor Approach

 Also called ”create-set-call” - approach

 Allows objects to be created and then initialized  Uniform construction approach among all objects

 Use exceptions at call time if necessary

FooClass foo = new FooClass(); foo.setBar(barValue); try { foo.use(); } catch (NoBarException e) { // react approprately } Default constructor example

slide-4
SLIDE 4

4

Required Constructor Approach

 Only provide specific constructors

 Method of ensuring proper initialization  Can guide the programmer to correct use

 Less flexible, but helps enforce invariants

FooClass foo = new FooClass(barValue); foo.use(); Required constructor example

slide-5
SLIDE 5

5

public class Socket { public Socket(String host) { ... this.setHost(host); } private String host; ... // getters and setters public void connect() { ... } }

Required vs. Default Constructor

 Compilte time vs. runtime handling

public class Socket { public Socket() { ... } private String host; ... // getters and setters public void connect() throws NoHostException { ... } } Socket with required constructor Socket with create-set-call

slide-6
SLIDE 6

6

Paper Conjecture

 Conjecture that required constructors

 ... create more usable and self-documenting APIs  … guide programmers toward correct use  … are therefore the correct approach for APIs

slide-7
SLIDE 7

7

Study Methodology

 Recruit 30 professional programmers  Give them programming tasks

 Using APIs with default / required constructors  Debugging code written in such APIs

 Gather audio and video material  Interview participants after the tasks

slide-8
SLIDE 8

8

Study Setup

 Room with one-way mirror  Cameras, audio recorder  Instructions to think out loud

slide-9
SLIDE 9

9

Programming Personas

 Observation: different styles of programming  Persona reflects work style only, not

programming proficiency

 3 different personas were analyzed in this study

Programmer Systematic Pragmatic Opportunistic

slide-10
SLIDE 10

10

3 Programming Personas

 Systematic programmer

 Top down, understand system as a whole

 Pragmatic programmer

 Bottom-up, but switch to top-down on fail

 Opportunistic programmer

 Get code working as quickly as possible  Don't understand more than necessary

slide-11
SLIDE 11

11

Selection Procedure

Systematic

Pragmatic Opportunistic Experience > 5 years > 2 years > 2 years Main language C / C++ C# Visual Basic Projects Large, focus

  • n reliability

GUI applications for windows Web applications

Recruitment criteria for different persona

slide-12
SLIDE 12

12

General Results

 Conjecture was not confirmed  Results of the study suggest

 More efficiency while using create-set-call  Programmers preferred create-set-call

Reminder: conjecture stated that required constructors are superior to create-set-call

slide-13
SLIDE 13

13

Task: File API Usage/Design

 Systematic programmers: design a file API  Others: write code without IDE

 Using file API the programmer would expect  Code should send contents of file by e-mail

Results

 All participants provided/used default constructors  Designed APIs also contained required constructors

slide-14
SLIDE 14

14

Task: Domain-Independent Classes

 Using objects in a setting with no prior intuition

 Plausible, but not understandable class names  Task consisted of correctly initializing object and

then calling use() function

 Compiler error vs. runtime exception

Results

 Many attempts to simply pass null  Exceptions more useful than compile errors

slide-15
SLIDE 15

15

Interview Results

 Nearly all participants preferred create-set-call

 Initialization flexibility – independent of creation  More control – error handling with return codes  Consistency  Less restrictive

slide-16
SLIDE 16

16

Study Limitations

 Official limitations

 Short tasks – advantage for default constructor ?  Generalization to other programming languages ?

 My opinion

 Very few participants – representative ?  Recruitment procedure justified ?

slide-17
SLIDE 17

17

Conclusion

 Study suggests that create-set-call

 ... is expected by many programmers  ... provides greater readability and debugability  ... gives the programmer control and flexibility

→ Write your APIs using default constructors!