[llvm-dev] [cfe-dev] Should functions returning bool return true or false on success?

James Courtier-Dutton via llvm-dev llvm-dev at lists.llvm.org
Wed Sep 19 15:04:45 PDT 2018


On 17 September 2018 at 18:57, Nico Weber via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi,
>
> in https://reviews.llvm.org/D52143 there's some uncertainty if LLVM code
> prefers
>
>   if (!Function())
>     // Call to function failed, deal with it
>
> or
>
>   if (Function())
>     // Call to function failed, deal with it
>
> (Note that this is about functions returning bool, not int.)
>
> Folks on that review feel that returning true on success is probably what
> we want, but it's not documented anywhere and we do have both forms in the
> codebase.
>
> True on success seems more common:
> http://llvm-cs.pcc.me.uk/?q=true+on+success
> http://llvm-cs.pcc.me.uk/?q=true+on+error
>
> Does anyone have a pointer to previous on-list discussion on this? If not,
> this thread could be the place where we sort this out once and for all :-)
>
> Apologies for the bike-sheddy topic.
>
> Nico
>
>
I would take the opinion that the code should be self documenting.
So, based on the function name, it should be obvious which it is.
e.g. Calling the function things like
isDigit()    the result is fairly obvious, it returns true if the item is a
digit.

Kind Regards

James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180919/cc5e370a/attachment.html>


More information about the llvm-dev mailing list