[...]
I think you mean, "there is no difference with respect to
readability".
That's a matter of (your) opinion, I'd guess most people
disagree with you about that, and there are certainly other
differences.
If I understand correctly what he's saying, I agree with him.
Typically, my boolean variables don't have the word "bool" in
them. (They do almost always start with "is" or "are", or
sometimes "has".) I think what he's trying to say is that the
name should reflect the meaning, and in the case of boolean
variables, the meaning includes the sense: "isActive" will be
true when whatever it concerns is active, and "isNotActive" will
be true when whatever it concerns is not active. The important
thing is that the name tells you what true and false signify.
(Note that this also means that it isn't good design to define a
function, "doSomething" which returns true of false to indicate
success or failure, since which indicates success isn't clear.
In such cases, it's better to have an enum, with values
succeeded and failed, and test them explicitly, i.e.:
if ( doSomething() ) ... // bad
if ( doSomething() == true ) ... // worse
if ( doSomething() == succeeded ) ... // good
.. Of course, if the name of the function somehow indicates
whether true or false is success, then there's no problem with
the first, above. And some idioms, like the implicit conversion
of istream or ostream, are so ubiquious that we can easily live
with them.)
Including the important one of not acquiring bad habits that
can have really undesired consequences in other contexts, and
the one about expressing code in a way that others are
familiar with and can easily read.
It's not helpful to put that much importance on a name in an
example.
Yes and no. The name is the thing. It's not helpful that he
chose a bad name, although the "is" is perhaps implicit.
Something like "if ( validity )" tells me nothing. With "if (
valid )", I can probably guess. And with "if ( isValid )", it's
100% clear.
And even with a name like 'x', use '!x' and not 'x == false'.
Agreed. Except that you shouldn't have a boolean named 'x'.