Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java boolean getters "is" vs "are"

I know that the convention in Java for boolean getters is include the prefix "is".

isEnabled isStoreOpen 

But what if the subject is plural? That is, what if instead of wanting to know if a store is open, I wanted to know if all the stores are open?

isStoresOpen() doesn't make sense in English.

I'm tempted to write getters like:

areStoresOpen areDogsCute areCatsFuzzy 

And I think that would make sense, but I've been told by others that I should just suck it up and abandon subject verb agreement and use isStoresOpen, isDogsCute, isCatsFuzzy.

Anyway, what should I do for boolean getters which operate on a plural subject?

like image 400
kodai Avatar asked Oct 18 '12 17:10

kodai


People also ask

Should Booleans 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.

Can you use == for boolean in Java?

Java boolean operators are denoted by |, ||, &, &&, <, >, <=, >=, ^, != , ==. These logical boolean operators help in specifying the condition that will have the two return values – “true” or “false”.

What is boolean [] in Java?

A Boolean expression is a Java expression that returns a Boolean value: true or false .


2 Answers

How about having decent enough english and following Java standard:

isEveryStoreOpen() or isEachCatCute()

When in doubt of the right word I always like to hit up the thesaurus.

like image 189
satur9nine Avatar answered Sep 22 '22 03:09

satur9nine


I can't remember which book this was from, but the essence is that code will be read many more times than it's written. Write for readability.

like image 35
John Avatar answered Sep 19 '22 03:09

John