HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMajor

Boolean naming convention

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
conventionbooleannaming

Problem

I have a class that stores the data related to all employees in a particular department.
In this class, I am having a list of employees and other fields.
Also, I am having a property which returns a bool, indicating whether an employee exists or not. I am a bit confused regarding the naming of this property.

class Employee_Details
{
  #region Private Fields
  private List employees;
  #endregion

  #region Fields
  // Gets a value indicating whether an employee exists
  public bool DoesEmployeeExists  // what should be the name of this property?
  {
    get
    {
      return this.employees.Any();
    }
  }
  #endregion      
}


Is the property name DoesEmployeeExists correct, or should I use any other name?

Solution

I would use simply HasEmployees.

In case of Boolean, I always try to use hasSomething or isSomething. In Java, many libraries use this strategy (it's just a convention). And I like it, because it's so easy to read when you see:

if(annoyingEmployee.isRemovable() && !annoyingEmployee.hasBirthday()) {
  manager.fireEmployee(annoyingEmployee);
}

Code Snippets

if(annoyingEmployee.isRemovable() && !annoyingEmployee.hasBirthday()) {
  manager.fireEmployee(annoyingEmployee);
}

Context

StackExchange Code Review Q#30914, answer score: 23

Revisions (0)

No revisions yet.