I suppose this could go down the rabbit's hole fast, but was curious:
If defining a global bool as true
bool production = true;
Then is it purely personal preference how to test between these two ways? I know there are other things to debate here, like curly braces..... this is just about testing the bool though.
if (production) {
publishToGoogleSheets();
}
vs
if (production == true) {
publishToGoogleSheets();
}
It is a personal thing.
I prefer the first one, but I would change the variable name. Production is not something that can be true or false.
Something like:
Since an if statement tests whether the condition evaluates to true, an == true seems redundant to me. We can keep adding == true until the cows come home.
So to make it clear - bool is a type of its own in C++, it denotes a truth value that can only be true or false (other values will get promoted into a truth value based on the usual non zero is true rule )
You would not say if it’s raining is true, you would just say if it’s raining, so the == true is useless esp if you named you variable appropriately to make the code easy to understand and maintain. (The good news is that the compiler will get rid of == true anyway so ….)