Tomas Petricek
email: t.petricek@kent.ac.uk
twitter: @tomaspetricek
office: S129A
Programming is trivial
The birth of a crisis
Software industry paradox (Ensmenger, 2010)
How can we explain the [seemingly perpetual] crisis
in what is considered one of the most successful and
profitable industries of all time?
How did software
get reliable?
Combination of good engineering practices
Management
Testing
Debugging
Over-engineering
Learning to live with errors
Over time, software engineers developed a range of practical approaches for coping with errors.
Depends on application domain
Business computing
Telecommunications
Computer art
Mistake - following a wrong plan
This logic is not actually going to sort a list
Failure - error in translation from plan to reality
My algorithm is correct, but I implemented it poorly
Slip - mechanical error when implementing code
Syntax error or off by one error in array access
Malfunction - hardware failures
Wrong data received in network communication
When do we find out?
Static error - when developing the software
Immediate runtime error
right when it occurs
Latent runtime error
sometime after it occurs
What can go wrong when executing a sub-routine?
Output error - no way of producing valid result
e.g. file does not exist
Input error - operation cannot be done because the inputs are wrong!
Input error - no character at index 99
1:
|
|
Input error - null
always represents invalid value
1:
|
|
Output error - there's no valid result if file doesn't exist
1:
|
|
Errors are inevitable
Good practices
Two ways of indicating errors
null
or -1
Why modern systems prefer exceptions?
Ignore bad inputs - assume that input is valid
1: 2: 3: |
|
When will this function not work?
The function will fail if name
is null
The function will fail if name
is empty string
Recover from bad inputs - try to do the best you can
1: 2: 3: 4: |
|
What happens for bad inputs?
You get an empty name as the result
Is this what you want? It depends...
Fail when input is bad - terminate execution immediately
1: 2: 3: 4: 5: |
|
Terminating execution immediately
Most languages support throwing exceptions
Exception to indicate what was wrong with input
Ignore bad inputs
Simple code, but unexpected things may happen
Good enough for local helper functions
Recover from bad inputs
Default behaviour may cause serious error later
Good if imperfect result is better than no result
Fail when input is bad
Stops execution, but tells you what to fix
Good for public functions called by others
Assume that your code might not be called correctly
Protect your code by throwing for bad inputs
Use extra security measures in low-level code
Check for null
values explicitly
Prevent errors using tests
Prove programs correct
Testing can only prove presence of bugs, not their absence. Rather than testing, we should prove programs correct.
The kill-yourself strategy
When the process does not know how to react, it should kill itself and let someone else deal with it.
In live coded music performance, there are no errors. Only more or less appropriate sounds. An error might be a source for creativity.
History, context and types of errors
Mistakes, failures, slips and malfunctions
Input errors and output errors
Engineering approach to error handling
Representing using error codes and exceptions
Three ways of handling bad inputs
Four more approaches to error handling
Mathematical proofs and engineering tests
Recovery in telecom and acceptance in art
What you should remember from this lecture
Tomas Petricek
t.petricek@kent.ac.uk | @tomaspetricek
Selected chapters from books
Papers and articles