I’ve been running into a good deal of bad computer code lately. Here’s an example from an actual tutorial. I’ve renamed the variable to protect the shameless:
if (count == 0) return false;
return true;
Why not this:
return (count != 0);
There are some god-forsaken languages in which returning the evaluation of a boolean expression is not valid (e.g. the creeping horror which goes by the name Open Office Basic). C and C++ are not among these. Yet, I’ve been running across a good dozen cases where the coders did not realize that.
In case someone would like to object: I know it is possible to just return count and let the compiler do an implicit conversion to bool but an explicit test makes the code clearer. The additional “if … then” does not.