en:software:matlab:trepr:dev:i:robust
Robust and Error-Tolerant
You cannot write an idiot-proof software, but you can try your best to prevent it from crashing in an unfriendly way.
Writing code that works well as long as you are careful only to provide the correct input and output is one thing. Writing code that is robust and can deal with the wrong number and type of input and output parameters something different.
Clearly, having the user in mind who is not an expert in programming nor in Matlab™ debugging, programming every function that is part of the toolbox as robust and save as possible is very important.
Developer's corner
For the time being, just a list of bullet points:
- Always check for type and number of input arguments of functions.
- Try to enclose your code with
try
-catch
statements. - Whereever possible, try to check for return values of function calls.
- Provide useful status messages that actually tell the user what's going on.
- Try not to use the
error()
function, as long as you are not sure that the exception this causes get's properly dealt with. Otherwise, you may break scripts/functions users have written using toolbox functions. - Check for the existence of variables/fields you want to use.
- This is particularly important in case of structures/cell arrays that are user-provided via the input parameters.
en/software/matlab/trepr/dev/i/robust.txt · Last modified: 2020/09/30 21:35 by 127.0.0.1