SlideShare une entreprise Scribd logo
1  sur  9
EDD (Error-Driven Development)
or: How I Learned to Stop Worrying and Love the
Exception
Consider the ways in which you system can go wrong
Categorize these error conditions
Programmer Error - Mistyped variable, null reference, type mismatch
Operational Error - Invalid user input, service outage, invalid user input
Determine how to handle these errors
Determine how to (or whether to) surface this error to the user
Write test cases for these error scenarios (error was thrown, message was logged, message was
displayed to user, etc.)
I - Think through error conditions before writing
the “happy path”
type Maybe a = Nothing | Just a
type alias User = {name: String, age: Maybe
Int}
Java:
Elm:
I (Cont.) - This Concept in Practice
public void writeList throws IOException, IndexOutOfBoundsException () {
type Result err val = Err err | Ok val
case String.toInt userInputAge of
Err msg -> span [class "error"] [text msg]
Ok age ->
if age < 0 then
span [class "error"] [text "Nuh Uh!"]
else if age > 140 then
span [class "error"] [text "Unlikely"]
else
text "OK!"
case user.age of
Nothing -> False
Just age -> age >= 21
Writing robust functions:
Assert arguments (and types) it expects
Assert additional constraints (e.g. must be a valid IP address)
Document all errors delivered by the function and throw as early as
possible, while providing all needed information to higher levels of the
stack
II - Design public functions to fail early on
programmer error
Side-Note: App-Code vs. Library-Code
Library-Code:
Never write to stdout! Instead,
allow the caller to configure a
logging function, or just throw an
exception with helpful information
Never surface relevant errors to
user. Instead, propagate them to
caller and let them handle
messaging
App-Code:
Write to stdout if that’s what your
logging solution requires
Surface relevant errors to user
Programs which do not handle operational errors are incorrect
The best way to recover from programmer errors is to crash immediately;
otherwise this error may propagate to other parts of the program with
unexpected results (most of us do this one really well already) 😉
If you don't know what errors can happen in your program, then it cannot be
correct except by accident
Other Takeaways
A function may deliver errors either synchronously or asynchronously, but
not both
If you receive something other than what a function is documented to accept,
that's a programmer error (i.e. it could have been avoided at compile-time)
Other Takeaways (Cont.)
References
1. http://guide.elm-lang.org/error_handling/
2. https://www.joyent.com/developers/node/design/errors (broken link 😢)
BONUS ROUND DESIGNER TIP!!!
Try to include basic error messaging locations in your
mockups. This lowers friction for lazy programmers who skip
good error messaging because “they don’t know where to
show them.”

Contenu connexe

Tendances

(6) cpp numeric representation_exercises
(6) cpp numeric representation_exercises(6) cpp numeric representation_exercises
(6) cpp numeric representation_exercisesNico Ludwig
 
Class Diagram Templates by Creately
Class Diagram Templates by CreatelyClass Diagram Templates by Creately
Class Diagram Templates by CreatelyCreately
 
Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.DrupalCampDN
 
Vulnerability assessment
Vulnerability assessmentVulnerability assessment
Vulnerability assessmentTechnical Hub
 

Tendances (6)

(6) cpp numeric representation_exercises
(6) cpp numeric representation_exercises(6) cpp numeric representation_exercises
(6) cpp numeric representation_exercises
 
Assignment 6
Assignment 6Assignment 6
Assignment 6
 
Class Diagram Templates by Creately
Class Diagram Templates by CreatelyClass Diagram Templates by Creately
Class Diagram Templates by Creately
 
Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.
 
Debugging
DebuggingDebugging
Debugging
 
Vulnerability assessment
Vulnerability assessmentVulnerability assessment
Vulnerability assessment
 

Similaire à EDD (Error Driven Development)

VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdfVISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdfNALANDACSCCENTRE
 
Exception handling
Exception handlingException handling
Exception handlingRaja Sekhar
 
debugging (1).ppt
debugging (1).pptdebugging (1).ppt
debugging (1).pptjerlinS1
 
An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...jeyasrig
 
Helpful logging with python
Helpful logging with pythonHelpful logging with python
Helpful logging with pythonroskakori
 
Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php Mudasir Syed
 
Marjan.nikolovski down the rabbit hole error handling examined-v01
Marjan.nikolovski down the rabbit hole   error handling examined-v01Marjan.nikolovski down the rabbit hole   error handling examined-v01
Marjan.nikolovski down the rabbit hole error handling examined-v01Marjan Nikolovski
 
Defect Tracking Software Project Presentation
Defect Tracking Software Project PresentationDefect Tracking Software Project Presentation
Defect Tracking Software Project PresentationShiv Prakash
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Javaankitgarg_er
 
UNIT-2-compiler design
UNIT-2-compiler designUNIT-2-compiler design
UNIT-2-compiler designkamaless4
 
The D language comes to help
The D language comes to helpThe D language comes to help
The D language comes to helpPVS-Studio
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software developmentHattori Sidek
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010Clay Helberg
 
Software Design
Software DesignSoftware Design
Software DesignSpy Seat
 
Searching for bugs in Mono: there are hundreds of them!
Searching for bugs in Mono: there are hundreds of them!Searching for bugs in Mono: there are hundreds of them!
Searching for bugs in Mono: there are hundreds of them!PVS-Studio
 
Building of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingBuilding of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingPVS-Studio
 

Similaire à EDD (Error Driven Development) (20)

VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdfVISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
 
Exception handling
Exception handlingException handling
Exception handling
 
debugging (1).ppt
debugging (1).pptdebugging (1).ppt
debugging (1).ppt
 
An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...
 
Error Messages In Software Applications
Error Messages In Software ApplicationsError Messages In Software Applications
Error Messages In Software Applications
 
Helpful logging with python
Helpful logging with pythonHelpful logging with python
Helpful logging with python
 
Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
 
Marjan.nikolovski down the rabbit hole error handling examined-v01
Marjan.nikolovski down the rabbit hole   error handling examined-v01Marjan.nikolovski down the rabbit hole   error handling examined-v01
Marjan.nikolovski down the rabbit hole error handling examined-v01
 
Introduction.pptx
Introduction.pptxIntroduction.pptx
Introduction.pptx
 
Defect Tracking Software Project Presentation
Defect Tracking Software Project PresentationDefect Tracking Software Project Presentation
Defect Tracking Software Project Presentation
 
Php exceptions
Php exceptionsPhp exceptions
Php exceptions
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
UNIT-2-compiler design
UNIT-2-compiler designUNIT-2-compiler design
UNIT-2-compiler design
 
The D language comes to help
The D language comes to helpThe D language comes to help
The D language comes to help
 
Lecture 20-21
Lecture 20-21Lecture 20-21
Lecture 20-21
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software development
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
Software Design
Software DesignSoftware Design
Software Design
 
Searching for bugs in Mono: there are hundreds of them!
Searching for bugs in Mono: there are hundreds of them!Searching for bugs in Mono: there are hundreds of them!
Searching for bugs in Mono: there are hundreds of them!
 
Building of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingBuilding of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code logging
 

EDD (Error Driven Development)

  • 1. EDD (Error-Driven Development) or: How I Learned to Stop Worrying and Love the Exception
  • 2. Consider the ways in which you system can go wrong Categorize these error conditions Programmer Error - Mistyped variable, null reference, type mismatch Operational Error - Invalid user input, service outage, invalid user input Determine how to handle these errors Determine how to (or whether to) surface this error to the user Write test cases for these error scenarios (error was thrown, message was logged, message was displayed to user, etc.) I - Think through error conditions before writing the “happy path”
  • 3. type Maybe a = Nothing | Just a type alias User = {name: String, age: Maybe Int} Java: Elm: I (Cont.) - This Concept in Practice public void writeList throws IOException, IndexOutOfBoundsException () { type Result err val = Err err | Ok val case String.toInt userInputAge of Err msg -> span [class "error"] [text msg] Ok age -> if age < 0 then span [class "error"] [text "Nuh Uh!"] else if age > 140 then span [class "error"] [text "Unlikely"] else text "OK!" case user.age of Nothing -> False Just age -> age >= 21
  • 4. Writing robust functions: Assert arguments (and types) it expects Assert additional constraints (e.g. must be a valid IP address) Document all errors delivered by the function and throw as early as possible, while providing all needed information to higher levels of the stack II - Design public functions to fail early on programmer error
  • 5. Side-Note: App-Code vs. Library-Code Library-Code: Never write to stdout! Instead, allow the caller to configure a logging function, or just throw an exception with helpful information Never surface relevant errors to user. Instead, propagate them to caller and let them handle messaging App-Code: Write to stdout if that’s what your logging solution requires Surface relevant errors to user
  • 6. Programs which do not handle operational errors are incorrect The best way to recover from programmer errors is to crash immediately; otherwise this error may propagate to other parts of the program with unexpected results (most of us do this one really well already) 😉 If you don't know what errors can happen in your program, then it cannot be correct except by accident Other Takeaways
  • 7. A function may deliver errors either synchronously or asynchronously, but not both If you receive something other than what a function is documented to accept, that's a programmer error (i.e. it could have been avoided at compile-time) Other Takeaways (Cont.)
  • 9. BONUS ROUND DESIGNER TIP!!! Try to include basic error messaging locations in your mockups. This lowers friction for lazy programmers who skip good error messaging because “they don’t know where to show them.”