Do not program "defensively"
September 25th, 2007
(From Erlang Programming Rules )
A defensive program is one where the programmer does not “trust” the input data to the part of the system they are programming. In general one should not test input data to functions for correctness. Most of the code in the system should be written with the assumption that the input data to the function in question is correct. Only a small part of the code should actually perform any checking of the data. This is usually done when data “enters” the system for the first time, once data has been checked as it enters the system it should thereafter be assumed correct.
Example:
%% Args: Option is all|normal
get_server_usage_info(Option, AsciiPid) ->
Pid = list_to_pid(AsciiPid),
case Option of
all -> 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 is responsible for supplying correct input.
Convention Equals Knowledge
June 8th, 2007
Convention Over Configuration为什么重要?
因为一个称手的约定俗成就是知识:关于“如何做某件事”的知识。
Struts只是给你无数种组织URL的可能性。换句话说,它没有告诉你“应该”如何组织URL。
Convention Over Configuration是在提供“可能性”的基础上,提供了“如何做”的知识,因此它简化使用者的工作。



