robust programmings

最近看了一些很烂的代码, 自己也在写这样的代码,对编程有了一些反思。

什么是robust program, 看看大牛的说法

can recover from expected error conditions

(intermittent failures, missing configuration files.)

can recover from unexpected error condition

(e.g file system full, our of disk quota, name lookup failures,

not enough resuources to draw a window ).

when there is an unrecoverable error - notifies the user of

the situation and cleanly shuts down.

avoids dependency on robustness of related processes

(a client should not crush because a server sent a

garbled reply and vice versa).

always check return values of system calls an library

functions - make this test exhaustive.

in any global function that accepts parameters-

check for their sanity(

pointers to data must not be NULL, data should no be out of range).

if a function might fail - have it return some error code

to its caller, don't just ignore the pssibility of failure.

when an inner function fails - it should return an error string to its caller - not just try

to display it to the user, exception:

the function can overcome the error and hider it from the calling function.

the function then may ignore the error, or issue a warning to the user,

depending on context. )

原文地址:https://www.cnblogs.com/kwingmei/p/3608717.html