Naming Booleans

If I only want to check if something is impossible or not (i.e. I will not use something like if(possible)), should I specify a logical notPossibleand use if(notPossible), or should I call it possibleand use it instead if(!possible)?

And to be sure, if I also need to check if it is possible, I would call the boolean possible and use if(possible)along with else, right?

+3
source share
9 answers

As a rule, I am mistaken on the side of positivity and use it possible. This means that someone cannot write code later that does this ...

if (!notPossible)

What is unreadable.

+4
source

You should probably use isPossible.

Negative names for boolean, such as notPossible, are very bad ideas. You may need to write things such as if (!notPossible)making it difficult to read code. Do not do this.

+6
source

, is has, not, "" (, , , , ;-) - isPossible ( !isPossible) isImpossible ( antonyms, has lacks, : -).

+1

, , . , , , .

, , , , . , , . , , , if (impossible && ...), if (!isPossible && ...).

+1

, . , "if (! NotPossible)".

0

, if (! notPossible).

0

isPossible. , "" (, , "" ) , , . , , -, ?

0

, - , , . , pathIsBlocked, cannotProceed, , , isNotAbleToDie, isImmortal.

0

, . , , isPossible. , isImpossible.

In any case, you can use elseif you need to check both cases.

From your description, it seems more important to you to check the impossibility, so I would go with isImpossible:

if(isImpossible)
{
    // ...
}
else
{
    //...
}
0
source

Source: https://habr.com/ru/post/1738731/


All Articles