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?
[Mandatory] Do not add 'is' as prefix while defining Boolean variable, since it may cause a serialization exception in some Java frameworks.
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”.
A Boolean expression is a Java expression that returns a Boolean value: true or false .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With