透明思考


Transparent Thoughts


Do not program "defensively"

(FromErlang Programming Rules)

A defensive program is one where the programmer does not “trust” the input data to thepart of the system they are programming. In general one should not test input data to functions forcorrectness. Most of the code in the system should be written with the assumption that the inputdata to the function in question is correct. Only a small part of the code should actually performany checking of the data. This is usually done when data “enters” the system for thefirst time, once data has been checked as it enters the system it should thereafter be assumedcorrect.

Example:
%% Args: Option is all|normalget_server_usage_info(Option, AsciiPid) -Pid = list_to_pid(AsciiPid),case Option ofall - get_all_info(Pid);normal - get_normal_info(Pid)end.
The function will crash if Option neither normal nor all, and it should do that. The caller isresponsible for supplying correct input.