Samuel Tardieu @ rfc1149.net

How should a program behave?

,

I always tell my compilation class students that there are two steps to follow when developping a new program:

  1. The program must accept any valid input and produce accurate results. The result of feeding the program with invalid input is undefined, it can either crash or silently produce wrong results.

  2. The program must reject any invalid input.

I see too many programmers try to implement the second phase before finishing the first one. It is true that implementing only the first one adds a burden onto the user, as he must provide valid input. But when the user makes no mistake, the program won’t either. However, as weird as it may seem, the second step is often the most difficult to achieve.

blog comments powered by Disqus