B
BartC
Bart van Ingen Schenau said:Would it still be counter-intuitive if you regard the result of an
application not as a boolean, but as a status code (with 0 == "success",
EXIT_FAILURE == "generic failure", other values more specific failure
codes)?
Or do you then also use 1 for success and several values of 0 to indicate
the various failures?
For status returns, the patterns I use tend to look like this:
o 1 = Success, 0 = Failure
Used when no further error codes are needed (or when there is a separate
step to obtain them).
This matches the logic typically used in programming:
if (do_it()) means it's done it. It would be odd to use it like this:
if (do_it()) puts("Couldn't do it!");
Even worse if the function was named done_it().
o N = Success, 0 = Failure
Where N encodes some data such as a file handle. This is used a lot in C
such as in malloc() and fopen().
I also use it for searches (in 1-based systems), where N is the index of
where something has been found, and 0 means not found.
o N>0 = Success, M<=0 means Failure (including N=1)
Where extra error info is needed; or more typically, where an 'out-of-band'
status is needed,
(for example on a dialog box where either item N is selected, or action M
has been clicked).
I don't use the 0 = Success, Anything Else = Failure pattern much at all,
except when an external API function happens to use it, or when 0 is part of
the data-range being returned.