jraskell:
In C++, int values will be automatically cast to bool values
You probably mean it correctly but the correct phrasing is
"In C++, the bool type is interchangeable with int values (casts in both direction);
In C, boolean values are int values;
in arduino, boolean value is a unsigned byte value
in arduino, bool maps to _Bool which is a native GCC type (but I'm not sure what it translates to)"
from the arduino code:
typedef uint8_t boolean;
from Boolean data type - Wikipedia
Standard C (since C99) and several dialects of C such as and Objective-C provide definitions of a Boolean type as an integer type and macros for "false" and "true" as 0 and 1, respectively. However, the initial standards for the C language (1972) provided no Boolean type, and to this day Boolean values are commonly represented by integers (ints) in C programs. The comparison operators ('>', '==', etc.) are defined to return a signed integer (int) result, either zero (for false) or 1 (for true). The same convention is assumed by the logical operators ('&&', '||', '!', etc.) and condition-testing statements ('if', 'while'). Thus logical values can be stored in integer variables, and used anywhere integers would be valid, including in indexing, arithmetic, parsing, and formatting. This approach ("Boolean values are just integers") has been retained in all later versions of C.
C++ has a separate Boolean data type ('bool'), but with automatic conversions from scalar and pointer values that are very similar to those of C. This approach was adopted also by many later languages, especially by some scripting ones such as AWK and Perl. One problem with this approach is that the tests if(t==TRUE){...} and if(t) are not equivalent. Python has a related situation, where the Boolean type, bool is a subtype of the integer type, int, and Booleans False and True act as 0 and 1, respectively, in arithmetic contexts.
The Pascal language (1978) introduced the concept of programmer-defined enumerated types. A built-in Boolean data type was then provided as a predefined enumerated type with values FALSE and TRUE. By definition, all comparisons, logical operations, and conditional statements applied to and/or yielded Boolean values. Otherwise, the Boolean type had all the facilities which were available for enumerated types in general — such as ordering and use as indices. On the other hand, the conversion between Booleans and integers (or any other types) still required explicit tests or function calls, as in ALGOL 60. This approach ("Boolean is an enumerated type") was adopted by most later languages which had enumerated types, such as Modula, Ada and Haskell.
After enumerated types (enums) were added to the ANSI version of C (1989), many C programmers got used to defining their own Boolean types as such, for readability reasons. However, enumerated types are equivalent to integers according to the language standards; so the effective identity between Booleans and integers is still valid for C programs.
but really this is splitting hairs.
Because there are many flavors (typedef/define/class) and in the end -as we are talking about code compatibility when using arduino- it hardly matters.
As to the original question about coding practice
I prefer
return true/false
to
return 0/1
when defining the method as boolean
but I quite often write
return Value>limit;
my most important coding practice rule is :"if you read this code in lets say 3 months from now; would you still understand what it does?"
If the answer is yes: go for it.
Best regards
Jantje