0

Please refer to Naming conventions for java methods that return boolean(No question mark)

to make a comparison about what I am NOT asking.

My question concerns properties derived from delegates embedded in a container object.

While the setters of all properties regardless of type is easily and conveniently prefixed with "set" (e.g. setValueRequired(blah) ), there are various types of boolean properties each whose getter is conventionally named {verb}{PropertyName}. e.g.,

  • the most common is existential, by convention is prefixed by "is". e.g. isEmpty().
  • possessive property, prefixed by "has", e.g. hasValue().
  • affirming necessity, prefixed by "requires", e.g. requiresResize(), providesResize().

By far, most property getters are somehow converted into existential properties. e.g. isRequireResize, isValued, etc. Therefore, my question concerns only expressing existential boolean properties (of a delegate class).

Let us say the container class is Printer, which contains the class Queue.

class Queue {
  boolean empty, resettable, resizable;
}

class Printer {
  Queue queue;
}

How then should Printer name its delegated properties for Queue? Because the following, by English comprehension convention, is awkward, as they sound like asking a question, not affirming its status.

  • isQueueEmpty()
  • isQueueResettable()
  • isQueueResizable()

The boolean property should be affirmative and not sound like asking a question. Therefore for comprehensible English, they should be

  • queueIsEmpty()
  • queueIsResettable()
  • queueIsResizable()

Or alternatively, could be

  • isEmptyQueue()
  • isResettableQueue()
  • isResizableQueue()

However, automated delegate method code generators invariably generate names isQueueEmpty(), isQueueResettable(), isQueueResizable().

That is awkward when placed into an if

if (isQueueResettable() && !isQueueEmpty()) resetQueue();

As this sounds better

if (isResizableQueue() && !isEmptyQueue()) resetQueue();

~
My Questions actually

  1. If there a JSR recommending naming conventions of property getters? What is it? Certainly there must be, otherwise wouldn't all the code generators out there be limping around with ambiguous conventions?

  2. If there is, does the JSR have recommendation for delegated boolean existential property getters?

  3. If not JSR, at least some form of RFCs in Apache, JBoss, Eclipse, etc?

  4. Don't you think the convention I recommend is better than code generators creating questioning getters?

Community
  • 1
  • 1
Blessed Geek
  • 21,058
  • 23
  • 106
  • 176

2 Answers2

0

I don't know much about JSR, but I am just trying to give my understanding.

You say isResettableQueue() sounds better than isQueueResettable to you( and probably to many others).

When you break up isResettableQueue() into is - Resettable - Queue, the main object(thing) about which you are talking comes into context at the last (in this case Queue).

But when you break up isQueueResettable() into is - Queue - Resettable, the main object(thing) about which you are talking comes into context at early stage (at least not at the last.

So you can tell Ok now I am talking about Queue for which I am checking if it is empty

Abubakkar
  • 15,488
  • 8
  • 55
  • 83
0

Method names should start with a verb, so queueIsEmpty shouldn't be used.

I can't find any articles about naming conventions that mention this particular case, but the most natural choice would still be isQueueEmpty. isEmptyQueue would refer to this instead of this.queue. It would return whether "This object is an empty queue" instead of "This object's queue is empty".

Oracle also uses method names on the form isQueueEmpty.

Here are relevant method names defined in AbstractButton, JFrame, JTable and their super-classes:

isAlwaysOnTopSupported, isBackgroundSet, isBorderPainted, isCellEditable, isCellSelected, isColumnSelected, isContentAreaFilled, isCursorSet, isFocusPainted, isFocusTraversalPolicySet, isFontSet, isForegroundSet, isMaximumSizeSet, isMinimumSizeSet, isOptimizedDrawingEnabled, isPreferredSizeSet isRequestFocusEnabled, isRolloverEnabled, isRootPaneCheckingEnabled, isRowSelected

Lone nebula
  • 4,768
  • 2
  • 16
  • 16
  • "but the most natural choice", using the term "natural" is like fraudulent organic food claimants, or anti-GM-food lobby or worse, the anti-marriage-equality bigots. The term has become meaningless. – Blessed Geek Jun 06 '13 at 22:39
  • I suppose I should have rather said "the most appropriate choice". The name should start with a verb, and `isEmptyQueue` is out of the question, so we're left with `isQueueEmpty` which is also what Oracle/Sun would most likely have picked (considering the names they've picked already). – Lone nebula Jun 07 '13 at 02:25