Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using "is" to name Boolean variables bad practice?

Is naming Booleans that start with "is" bad practice now? My manager believes that "isAnything" is outdated and poor practice. Is this true?

myManager.isLame ? correct() : incorrect(); 
like image 720
worked Avatar asked Aug 05 '11 02:08

worked


People also ask

Should Boolean variables start with is?

[Mandatory] Do not add 'is' as prefix while defining Boolean variable, since it may cause a serialization exception in some Java frameworks.

How should Booleans be named?

When naming booleans, you should avoid choosing variable names that include negations. It's better to name the variable without the negation and flip the value. If you absolutely can't (see Guideline 2 below), then try to find an already-negated form of the concept you are trying to express.

Which is the correct way to declare a Boolean variable value to be true?

To declare a Boolean variable, we use the keyword bool. To initialize or assign a true or false value to a Boolean variable, we use the keywords true and false.


1 Answers

It's used quite often in a lot of languages, but I don't know if it can be said with certainty that it's the preferred method.

I think consistency and everyone on a given team using the same standards/styles is the important thing to bear in mind.

like image 172
Tim Avatar answered Sep 30 '22 17:09

Tim