views:

103

answers:

6

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?

+6  A: 

Please don't use isPointersNull. Consistency is no reason to sacrifice on grammar and readability.

froadie
+1 - I agree arePointersNull is better. You could also have PointersAreNull then an If statement clarity would be even better.
ChrisBD
+9  A: 

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.

Adam Robinson
A: 

IMO - depends on the context (usage & readability) of the boolean variable.

For example:
- if the variable is referring to a single pointer being null, I would use: isPointerNull
- if the variable is referring to multiple pointers being null, I would use: arePointersNull

HTH.

Sunny
+3  A: 

It depends on the language. If you are using Java, 'isPointersNull' will be interpreted as the 'pointersNull' field where 'arePointersNull' will not if you are using any JavaBean processing tools.

I agree that readability is paramount but bean conventions allow common parsing of objects.

Chris Dail
well put chris. even though a method name may not make sense to us a lot of tools expect you to stick to standard conventions like JavaBean syntax and you'll trip yourself up if you stray....only to end up conforming to the standard in the end.
tmeisenh
A: 

isPointersNull looks like a typo. arePointersNull communicates nicely the fact that more than a single object is involved in the consideration of this boolean. But if you want consistency you could refer to an array or collection, which your Pointers ought to be:

  • isPointerArrayNull
  • isPointerCollectionEmpty
  • etc.
Paul Sasik
While does it communicate nicely that we're talking about multiple items, does it mean that *more than one is null* (and some may be non-null), or does it mean that *there is more than one pointer, and they're all null*?
Adam Robinson
A: 

I personally go with isWhatever if I am referencing the getter method of a boolean variable no matter how ugly it is according go grammar rules. But if I had a method that did some sort of checking of an object based on some businessy-rule (like if a number or numbers is/are prime) I would use names that would make my English teachers happy.

tmeisenh