New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return codes for success and failure (int
, bool
)
#6436
Comments
New functions should use bool return types in my opinion. |
Should they return |
true for success of course. |
For functions returning different kinds of errors I'm honestly not sure how best to handle them, should they maybe be using |
For |
true for success bools to convey the meaning instead of int |
|
How do we want to communicate success and failure in the code base? According to #6429 (comment), we're currently using 0 as success and non-0 as failure for functions returning
int
. We usetrue
as success andfalse
as failure for functions returningbool
.These are currently opposites, and since you can't see (at a call site) whether a function returns
int
orbool
, it seems error-prone to me. I think it'd make sense to unify this somehow. E.g. #6429 moves this towardstrue
for success.@Robyt3 argues that he finds
if(function()) { /* success */ }
more readable thanif(function()) { /* failure */ }
.For functions returning different kinds of errors, it might make more sense to treat 0 as success because there's usually one success path but many failure paths. I'm not sure if we even use that in the code base.
str_hex_decode
returns multiple error codes, but I don't think they're used by any caller.Prior art
curl uses 0 as success. zlib uses 0 as success. WINAPI mostly uses non-0 as success. I think most POSIX APIs that don't return a value use 0 as success.
The text was updated successfully, but these errors were encountered: