List:Internals« Previous MessageNext Message »
From:Davi Arnaut Date:September 8 2010 4:02pm
Subject:Re: [STYLE] use true/false in C++, not TRUE/FALSE
View as plain text  
On 9/8/10 12:40 PM, Michael Widenius wrote:
>
> Hi!
>
>>>>>> "Davi" == Davi Arnaut<davi.arnaut@stripped>  writes:
>
> Davi>  On 8/31/10 2:51 PM, Vladislav Vaintroub wrote:
>
> <cut>
>
> Davi>  C has a different rule, whereas there can be truncation. For example, a
> Davi>  larger int might be truncated when converting to my_bool, resulting in a
> Davi>  false.
>
> In this case you will get a warning from most compilers.

No. Implicit integer conversion is quite common, no sane compiler will 
give such warning by default. Even if we activated it for MySQL code, it 
would be lost in a sea of warnings as MySQL code is quite crappy in this 
regard.

> Davi>  Just say *no* to Boolean in C. I actually worry when I see a return type
> Davi>  of my_bool and a return value other than TRUE/FALSE. Better stick with a
> Davi>  simple int in C code.
>
> Which is a cause for creating more possiblity for errors not less.

In your opinion.

> For example:
>
> my_bool foo() { return 5 };
> int foo() { return 5 };

No one does this.

> It's more clear that the first code example contains an error than the last
> one.

Of course it is more clear, but no one does this. The common pattern 
that I've seen is a returning the value of a variable whose type is not 
my_bool.

> Declaring a function to be my_bool will make it clear that one can't
> just change the function to return something else than 0 or 1 as those
> calling the function would not expect a value of '5'.

This has nothing to do with what I was arguing. Your argument is mainly 
about the cosmetics of using my_bool and does not take into account the 
underlying type of my_bool.

My argument was that there is no proper type for my_bool and this 
renders it useless.  Making cosmetic changes to a function return type 
is a futile attempt to disguise its true nature. This is a good example 
of lipstick on a pig.

The proper way to avoid such bugs is to have proper documentation and 
review process which will not approve such kind of changes. If a 
developer makes such kind of changes and no one complains, we already lost.

Regards,

Davi Arnaut
Thread
[STYLE] use true/false in C++, not TRUE/FALSEGuilhem Bichot26 Aug
  • Re: [STYLE] use true/false in C++, not TRUE/FALSERoy Lyseng26 Aug
  • Re: [STYLE] use true/false in C++, not TRUE/FALSEMARK CALLAGHAN26 Aug
    • Re: [STYLE] use true/false in C++, not TRUE/FALSEGuilhem Bichot31 Aug
      • Re: [STYLE] use true/false in C++, not TRUE/FALSEMARK CALLAGHAN31 Aug
        • Re: [STYLE] use true/false in C++, not TRUE/FALSEGuilhem Bichot31 Aug
          • Re: [STYLE] use true/false in C++, not TRUE/FALSEJay Pipes31 Aug
            • Re: [STYLE] use true/false in C++, not TRUE/FALSEDavi Arnaut31 Aug
              • Re: [STYLE] use true/false in C++, not TRUE/FALSEJay Pipes31 Aug
                • Re: [STYLE] use true/false in C++, not TRUE/FALSEDavi Arnaut31 Aug
                  • Re: [STYLE] use true/false in C++, not TRUE/FALSEMARK CALLAGHAN31 Aug
                    • Re: [STYLE] use true/false in C++, not TRUE/FALSEDavi Arnaut31 Aug
                      • Re: [STYLE] use true/false in C++, not TRUE/FALSEMARK CALLAGHAN31 Aug
                        • Re: [STYLE] use true/false in C++, not TRUE/FALSERoy Lyseng31 Aug
                          • Re: [STYLE] use true/false in C++, not TRUE/FALSEMARK CALLAGHAN31 Aug
                            • Re: [STYLE] use true/false in C++, not TRUE/FALSEMichael Widenius8 Sep
                              • Re: [STYLE] use true/false in C++, not TRUE/FALSEJay Pipes8 Sep
                          • RE: [STYLE] use true/false in C++, not TRUE/FALSEVladislav Vaintroub31 Aug
                            • Re: [STYLE] use true/false in C++, not TRUE/FALSERoy Lyseng31 Aug
                            • Re: [STYLE] use true/false in C++, not TRUE/FALSEDavi Arnaut31 Aug
                              • Re: [STYLE] use true/false in C++, not TRUE/FALSEMichael Widenius8 Sep
                                • Re: [STYLE] use true/false in C++, not TRUE/FALSEDavi Arnaut8 Sep
                                  • RE: [STYLE] use true/false in C++, not TRUE/FALSEVladislav Vaintroub8 Sep
                        • Re: [STYLE] use true/false in C++, not TRUE/FALSEMichael Widenius8 Sep
                      • Re: [STYLE] use true/false in C++, not TRUE/FALSEKonstantin Osipov8 Sep
                        • Re: [STYLE] use true/false in C++, not TRUE/FALSEMats Kindahl8 Sep
                          • Re: [STYLE] use true/false in C++, not TRUE/FALSETor Didriksen8 Sep
                            • Re: [STYLE] use true/false in C++, not TRUE/FALSEMats Kindahl8 Sep
                              • RE: [STYLE] use true/false in C++, not TRUE/FALSEVladislav Vaintroub8 Sep
                                • Re: [STYLE] use true/false in C++, not TRUE/FALSEMats Kindahl8 Sep
                              • Re: [STYLE] use true/false in C++, not TRUE/FALSETor Didriksen8 Sep
                                • Re: [STYLE] use true/false in C++, not TRUE/FALSEMats Kindahl8 Sep
                  • Re: [STYLE] use true/false in C++, not TRUE/FALSEJay Pipes31 Aug
        • Re: [STYLE] use true/false in C++, not TRUE/FALSEMichael Widenius8 Sep
      • Re: [STYLE] use true/false in C++, not TRUE/FALSEMARK CALLAGHAN31 Aug
  • Re: [STYLE] use true/false in C++, not TRUE/FALSEMats Kindahl27 Aug
    • Re: [STYLE] use true/false in C++, not TRUE/FALSEMichael Widenius8 Sep