Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming booleans

If I only want to check if something is impossible or not (i.e., I will not be using something like if(possible)), should I name the boolean notPossible and use if(notPossible) or should I name it possible and use if(!possible) instead?

And just to be sure, if I also have to check for whether it is possible, I would name the boolean possible and use if(possible) along with else, right?

like image 568
wrongusername Avatar asked Oct 11 '25 20:10

wrongusername


1 Answers

You should probably use isPossible.

Negative names for booleans like notPossible is a very bad idea. You might end up having to write things like if (!notPossible) which makes the code difficult to read. Don't do that.

like image 189
Mark Byers Avatar answered Oct 16 '25 08:10

Mark Byers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!