[Maria-developers] TRUE vs true (was: [Commits] ac05f41: postreview fix)
Hi, Jan! On 23.04.15 08:38, Jan Lindström wrote:
Sanja,
Why you use TRUE/FALSE instead of true/false for bool ? Historical reasons. I was told to use TRUE/FALSE long time ago and nobody have told something else. We have no our code style doc so I use what I remember from old MySQL one.
[skip]
Hi, I would like to point out that it would be a good idea to start writing our own coding style doc, so that we no longer have these sort of unknowns. It also helps the community provide patches that are easier for us to review. I can start working on it myself. Regards, Vicențiu On Thu, 23 Apr 2015 at 10:33 Oleksandr Byelkin <sanja@montyprogram.com> wrote:
Hi, Jan!
On 23.04.15 08:38, Jan Lindström wrote:
Sanja,
Why you use TRUE/FALSE instead of true/false for bool ? Historical reasons. I was told to use TRUE/FALSE long time ago and nobody have told something else. We have no our code style doc so I use what I remember from old MySQL one.
[skip]
_______________________________________________ Mailing list: https://launchpad.net/~maria-developers Post to : maria-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~maria-developers More help : https://help.launchpad.net/ListHelp
Hi! According to MySQL coding guidelines: https://dev.mysql.com/doc/internals/en/additional-suggestions.html <quot> * In C code, use TRUE and FALSE rather than 1/0 * In C++ code, it is OK to use true and false (do not use 1/0). You can use C++ bool/true/false when calling C functions (values will be safely promoted to my_bool). </quot> I'm aware of only one more or less good reason for not using true/false in C++: it's easier to convert it to C code. But that's rare: we mostly convert in the opposite direction. Also C99 now supports true/false, e.g. see nice description: http://www.jacquesf.com/2011/04/in-defense-of-the-c99-boolean-type/ Regards, Sergey On Thu, Apr 23, 2015 at 09:33:07AM +0200, Oleksandr Byelkin wrote:
Hi, Jan!
On 23.04.15 08:38, Jan Lindström wrote:
Sanja,
Why you use TRUE/FALSE instead of true/false for bool ? Historical reasons. I was told to use TRUE/FALSE long time ago and nobody have told something else. We have no our code style doc so I use what I remember from old MySQL one.
[skip]
_______________________________________________ Mailing list: https://launchpad.net/~maria-developers Post to : maria-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~maria-developers More help : https://help.launchpad.net/ListHelp
Hi, Sergey! Yup. I use TRUE/FALSE for my_bool in C and true/false for bool in C++. With the only expection of return values where 0 conventionally means success and non-zero means an error. As Mark Callaghan once commented bool somefunc() { ... /* got an error */ return true; ... /* finished successfully */ return false; } looks pretty weird. I agree that true for an error and false for a success is kind of counter-intuitive. So in this case I use 1 and 0. Regards, Sergei On Apr 23, Sergey Vojtovich wrote:
Hi!
According to MySQL coding guidelines: https://dev.mysql.com/doc/internals/en/additional-suggestions.html
<quot> * In C code, use TRUE and FALSE rather than 1/0
* In C++ code, it is OK to use true and false (do not use 1/0). You can use C++ bool/true/false when calling C functions (values will be safely promoted to my_bool). </quot>
I'm aware of only one more or less good reason for not using true/false in C++: it's easier to convert it to C code. But that's rare: we mostly convert in the opposite direction.
Also C99 now supports true/false, e.g. see nice description: http://www.jacquesf.com/2011/04/in-defense-of-the-c99-boolean-type/
Regards, Sergey
On 23.04.15 10:14, Sergey Vojtovich wrote:
Hi!
According to MySQL coding guidelines: https://dev.mysql.com/doc/internals/en/additional-suggestions.html
<quot> * In C code, use TRUE and FALSE rather than 1/0
* In C++ code, it is OK to use true and false (do not use 1/0). You can use C++ bool/true/false when calling C functions (values will be safely promoted to my_bool). </quot>
"It is OK" == "it is allowed to use it." (about true/false) you have not use 1/0 and TRUE/FALSE must in C and OK in C++ (there is no other told) So I should carefully check what code it is or just use TRUE/FALSE? I prefer TRUE/FALSE everywhere. [skip]
Hi Sanja, yes, it is not a requirement to use true/false in C++. I'd be Ok about my_bool if not one glitch: it can evaluate to anything that char can evaluate to. C99 bool behaves more as expected: <quot> _Bool (also accessible as the macro bool) - type, capable of holding one of the two values: 1 and 0 (also accessible as the macros true and false). Note that conversion to _Bool does not work the same as conversion to other integer types: (bool)0.5 evaluates to 1, whereas (int)0.5 evaluates to 0. </quot> I'd vote for bool/true/false everywhere if I were sure about it's portability and about sizeof(_Bool) stability. Regards, Sergey On Thu, Apr 23, 2015 at 11:02:16AM +0200, Oleksandr Byelkin wrote:
On 23.04.15 10:14, Sergey Vojtovich wrote:
Hi!
According to MySQL coding guidelines: https://dev.mysql.com/doc/internals/en/additional-suggestions.html
<quot> * In C code, use TRUE and FALSE rather than 1/0
* In C++ code, it is OK to use true and false (do not use 1/0). You can use C++ bool/true/false when calling C functions (values will be safely promoted to my_bool). </quot>
"It is OK" == "it is allowed to use it." (about true/false)
you have not use 1/0
and TRUE/FALSE must in C and OK in C++ (there is no other told)
So I should carefully check what code it is or just use TRUE/FALSE?
I prefer TRUE/FALSE everywhere.
[skip]
On 24.04.15 08:29, Sergey Vojtovich wrote:
Hi Sanja,
yes, it is not a requirement to use true/false in C++.
I'd be Ok about my_bool if not one glitch: it can evaluate to anything that char can evaluate to. C99 bool behaves more as expected: <quot> _Bool (also accessible as the macro bool) - type, capable of holding one of the two values: 1 and 0 (also accessible as the macros true and false). Note that conversion to _Bool does not work the same as conversion to other integer types: (bool)0.5 evaluates to 1, whereas (int)0.5 evaluates to 0. </quot>
I'd vote for bool/true/false everywhere if I were sure about it's portability and about sizeof(_Bool) stability.
I have nothing against true/false. When (if?) we will have our style book I will vote for it, but now I use what I used to (IMHO it is good explanation to the original question).
participants (4)
-
Oleksandr Byelkin
-
Sergei Golubchik
-
Sergey Vojtovich
-
Vicențiu Ciorbaru