Question Details

No question body available.

Tags

java naming

Answers (3)

April 8, 2025 Score: 4 Rep: 2,659 Quality: Medium Completeness: 80%

The use of a verb (is, get) for a method goes hand in hand with the use of noun/adjective for a variable/field.

boolean selected = line.isSelected();
boolean lineSelected = line.isSelected();

Mind that this convention is not very tight in this field as opposed to word capitalization. For booleans one the possible formulations - when a noun is used:

  • as predicate (noun-is-adjective) or

  • as question (is-noun-adjective).

    boolean lineSelected = line.lineIsSelected();
    boolean lineSelected = line.isLineSelected(); // UGLY IMHO
    boolean multipleRowsSelected = table.multipleRowsAreSelected();
    boolean multipleRowsSelected = table.areMultipleRowsSelected(); // UGLY IMHO
    

Though the question form has a prefix systematic, always is/are in front. But a predicate is more operational correct.

With respect to using are. That really is acceptable, as many predicates have other verbs like have or contains.

Also one often can see the compound structure exposed; something like:

table.getSelectionMode().isMultiple()

Some other perspectives

Getters and setters are a bit tainted or at least called boiler plate code. Other styles exist. Argumently not much better is the latest style of the java record classes:

record Point(int x, int y) {};
Point pt = new Point(3, 4);
int  x = pt.x();

And similar:

int x = obj.x(); // Getter.
obj.x(30); // Setter.

Here every categpry is generalized to a noun. A kind of Chinese.

April 8, 2025 Score: 3 Rep: 85,992 Quality: Medium Completeness: 60%

IsX has become conventional and thus has some usability benefits. We see IsX and know it's a boolean flag.

But I would advise against trying to make your methods follow english grammar too closely.

For the same reason you avoid plurals, for every case where a choice makes you code grammatical, there is a case where it makes it ungrammatical or ugly.

obj.IsX = true; //ungrammatical
if(obj.IsX) //grammatical
people.add(person) //grammatical
foreach(person in people)  //hmmmm
people.contains(person) //???!
personList.contains(person) //grammatical in more cases.

For your specific case of table.multipleRowsSelected It seems like it's already covered by table.getSelectedRows().length > 1, but if you really need it then yes I would switch to an IsSomething rather than table.AreMultipleRowsSelected.

Has is almost as popular as Is so..

table.HasMultipleRowsSelected

Or Maybe you could do a combination of

table.IsAnyRowSelected && ! table.IsSingleRowSelected

Or if you need to differentiate these tables in a general sense, you can choose a noun.

table.IsMultiplex

If you use this across the board you can talk about "multiplex tables" and everyone knows what you mean.

April 8, 2025 Score: 2 Rep: 49,734 Quality: Low Completeness: 10%

Obviously “is” is stupid if it’s not true. You may have prefixes like “has” (like a button is not a title, but a button can have a title). Or “can” (you can paste text into a text field but not an audio file), or other suffixes describing correctly what the result of the Boolean function is.