return boolean from functions

Thomas Wouters thomas at xs4all.nl
Fri Nov 5 09:59:50 EST 1999


On Fri, Nov 05, 1999 at 02:16:03PM +0000, Preston Landers wrote:

> and false for fail.  That's fine if that works for you, but FYI the
> convention in Unix[1] is generally to return false for success, and true
> for an error condition.  This way the exact condition can be contained

That depends on what part of UNIX you mean :-) In UNIX shell programming,
where 'true/false' is based on the exit codes of programs, '0' means
success, and something non-zero means failure. But it just means '0' is
true, not that 'false means success'. The UNIX tool 'true' returns '0':

centurion:~ > /bin/true
centurion:~ > echo $?
0

Of course, if you call 'exit(0)' in your program, you are sort-of 'returning'
a false value to signify success -- but it's only false in C evaluations,
not in shell evalutations. Look at it like not 'returning' 0, but 'exiting
with 0 errors'. Or something.

A lot of the UNIX library calls return '-1' for failure, especially when
both '0' and '1' can be valid returns. Some return a code to indicate which
error occured, where 0 might mean 'no error'. Some always return an error,
and some never return :)

conventions-conschmentions'ly y'rs,
-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list