Is this a bad practice? On the one hand, you are doing an implicit casting, which I feel like is sorta slow.
On the other hand, bool is such a small data type I wonder if casting it is rather inexpensive. Should I tell these guys to not return an int or to just let this code be?
The performance difference is likely completely negligible, although I've never benchmarked it. This is more a question of style than performance. Stylistically I'd prefer to return true or false when the function return type is bool.
Why not just return numItems == 0; to avoid both implicit conversions and redundant code and, to appease some purists, multiple exit points?
In any case, the compilers aren't that dumb: this function compiles into two CPU instructions on intel cpus: testl or cmpl followed by sete or cmove, depending on the compiler. Using true/false instead of 1/0 does not change the code.
In any case, the compilers aren't that dumb: this function compiles into two CPU instructions on intel cpus: testl or cmpl followed by sete or cmove, depending on the compiler. Using true/false instead of 1/0 does not change the code.