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/FALSE | Guilhem Bichot | 26 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Roy Lyseng | 26 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 26 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Guilhem Bichot | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Guilhem Bichot | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Jay Pipes | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Jay Pipes | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Roy Lyseng | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Jay Pipes | 8 Sep |
| • RE: [STYLE] use true/false in C++, not TRUE/FALSE | Vladislav Vaintroub | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Roy Lyseng | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 8 Sep |
| • RE: [STYLE] use true/false in C++, not TRUE/FALSE | Vladislav Vaintroub | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Konstantin Osipov | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Tor Didriksen | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 8 Sep |
| • RE: [STYLE] use true/false in C++, not TRUE/FALSE | Vladislav Vaintroub | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Tor Didriksen | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Jay Pipes | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 27 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |