Naming convention: Negative Booleans

I would like a rule that identifies Boolean variables or methods that return a Boolean that are named in the negative, because they make the code very difficult to read due to double negatives and even triple negatives.

Example:
Boolean isNotActive = false; // It is not not active, so it’s active… right?
if(!isNotActive){ // Ok, so if it is not not active, we do something…
// do thing
}else{ // And if it is not not not active do something else…
// do other thing
}

Booleans should always be named in the affirmative to make code more readable.

Example:
Boolean isActive = true; // It’s active
if(isActive){ // If it is active, do something
// do thing
}else{ // If it is not active, do something else…
// do other thing
}

2 Likes