190R6 Reliable & Robust Coding

When we write code that will interact with users we make a range of assumptions about what that user will do. Not everything they do will be appropriate, it may sometimes be malicious, or simply in error, and programmers must prepare for these events.

 


Reliable Code

Reliable code will provide consistent results from the full range of its specifications, without any failures.

  • identifying and controlling the inputs (data)
  • able to handle exceptions (error handling)
  • fully tested and regularly reviewed code

Reliable code is naturally secure.

Robust Code

Robust code is fully able to continue to function and perform to a high standard even when experiencing strange or unexpected events (eg. interruptions, early termination, network problems, etc). Good quality code handles these errors and provides meaningful error messages to the user. These error messages help the programmer and the end user to more easily resolve issues and debug the program.

Designing robust programs benefit from:

  1. validation – protection against unexpected user inputs or actions, such as a user entering a letter where a number was expected
  2. authentication  – confirming that users on a computer system are who they say they are
  3. testing – finding and minimising errors
  4. error messages – providing meaningful information and correct instructions

Test data is data that checks whether or not a program is functioning correctly. Ideally, test data should cover a range of possible and impossible inputs, any errors should generate sensible human readable error messages.

Three types of test data are:

  1. normal data – typical, sensible (ie correct) data that the program can process successfully
  2. boundary data – valid data that falls at the boundary of possible ranges, sometimes known as extreme data
  3. erroneous data – data that the program cannot process and should not accept

 

Ex 1

If you were building a system that handles personal details (eg for shopping), give examples of how you could test the different types of data the user will input to ensure it is valid and not cause the program to fail.