Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is or Are to prefix boolean values

Tags:

When naming a boolean, or a function returning a boolean it's usual to prefix with 'is' e.g.

  • isPointerNull
  • isShapeSquare

What about when refering to multiple items, should it be:

  • arePointersNull or isPointersNull
  • areShapesNull or isShapesNull

I can see arguments for both; is offers consistency and perhaps slightly better readability, are makes the code read in a more natural way.

Any opinions?

like image 665
satnhak Avatar asked Apr 22 '10 14:04

satnhak


People also ask

Should you prefix boolean with is?

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

Do you use or == for boolean?

Boolean values are values that evaluate to either true or false , and are represented by the boolean data type. Boolean expressions are very similar to mathematical expressions, but instead of using mathematical operators such as "+" or "-", you use comparative or boolean operators such as "==" or "!".

What is prefix used in declaring a boolean?

Boolean variables should be prefixed with 'is' This is the naming convention for boolean methods and variables used by Sun for the Java core packages. Using the is prefix solves a common problem of choosing bad boolean names like status or flag.

Are for boolean variables?

Boolean variables can either be True or False and are stored as 16-bit (2-byte) values. Boolean variables are displayed as either True or False. Like C, when other numeric data types are converted to Boolean values then a 0 becomes False and any other values become True.


1 Answers

Firstly, isPointersNull is just ugly. Don't do that.

I typically go with any or all, as are can be ambiguous. Does it mean "there are null pointers" or "the pointers are all null"? anyPointersNull and allPointersNull clear that up, IMO.

like image 187
Adam Robinson Avatar answered Sep 28 '22 03:09

Adam Robinson