I seem to recall that there is a specific term for an accessor method that returns a Boolean value but it escapes me. For example: typical methods such as:

class Example {
    bool isDirty();
    bool hasChildren();
    bool isValid(SomeType obj);

I will also settle for such a term as applied to a non-member functions.

  • While 'is' is generally good enough, it is important to not use 'not' after 'is' otherwise the meaning becomes confusing, for example this obviously bad: isNotGood. – NoChance Feb 14 '12 at 13:40
  • 1
    Yes thanks but what I am really looking for is not a naming convention but rather a term for the whole class of these simple boolean member functions. – David Wheaton Feb 14 '12 at 13:44
  • 1
    "Accessor methods that return booleans." Not everything needs a name. – Blrfl Feb 14 '12 at 14:55
  • @Emmad: I think list.isNotEmpty() is more readable than !list.isEmpty() – Codism Feb 14 '12 at 21:02
  • @Codism, both are readable, in my case, the 'not' part takes more brain cells to figure :) – NoChance Feb 15 '12 at 7:47

A function from some type T to Boolean is usually called a predicate, and if you want to make clear that it is a method of an object, i.e. that it takes the implicit this argument in addition to its other arguments, then you could call it a predicate method. If it takes no other arguments except the implicit this argument, then you can call it a predicate property.

See for example Predicate<T> in .NET and e.g. javax.sql.rowset.Predicate or com.google.common.base.Predicate in Java.

| improve this answer | |
  • 1
    +1: Shout out to David Parnas www-public.int-evry.fr/~gibson/Teaching/MAT7003/ReadingMaterial/… – dietbuddha Feb 14 '12 at 18:19
  • why the "no other arguments" thing? i'd say that isBiggerThan(x) is a predicate – Javier Feb 14 '12 at 19:06
  • Yes predicate is the term I had forgotten... Thanks for refreshing my memory! – David Wheaton Feb 14 '12 at 21:11
  • FYI: In Common Lisp the name of predicate functions (should) end with the letter p - so that everyone knows exactly what it is. In languages like Ruby and Clojure the convention is to end the name with a questionmark. – Torbjørn Feb 14 '12 at 22:09
  • @Javier: you're right. I think predicate property would be a better term for that. I'll change the answer. – Jörg W Mittag Feb 15 '12 at 1:48

If the method is simply returning an attribute of the object, I would call it an accessor, since it is simply used to access a private member variable of the object.

If the method performs some kind of computation or contains logic (beyond the possibility of logging or validation), it's simply a method. It's no different than a method that performs any other operations that use the state of the object and return a value that's not a boolean.

If the method preforms some special task, such as checking equality or validity, I might want to refer to it by what it does, such as calling it a "validator method" or "equality method". Those names is a bit shorter than saying "a method that checks the validity of the object" or "a method that checks the equality of this object against another".

Not everything has a special name, though. Call it by what it is.

| improve this answer | |

A switch (which is ambiguous), a flag, a bool, a state... Nothing I can think of is specific to a getter...

Different environments have different conventions...

Ruby: some_object.is_something?

ObjC: [someObject isSomething]

So I guess I support the "is doctrine"...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.