Which is more conventional function name between "ContainsElement" and "DoesContainElement"?

71 Views Asked by At

I'm writing a function to determine whether an element exists in a container. I don't know how to choose the function name between:

bool ContainerType::ContainsElement(const ElementType& elem);

and

bool ContainerType::DoesContainElement(const ElementType& elem);

Consider the following two scenario:

Version 1:

ContainerType coll;
ElementType   elem;
...

if (coll.ContainsElement(elem))
{
    cout << elem << " exists." << endl;
}

Version 2:

ContainerType coll;
ElementType   elem;
...

if (coll.DoesContainElement(elem))
{
    cout << elem << " exists." << endl;
}

As I understand it, I think version 1 is more like natural English. However, I also found version 2's style is used more widely.

What's your opinion?

Update:

FltIsOperationSynchronous
FltIsIoCanceled
FltIsVolumeWritable

The three function names above are excerpted from Microsft's documentation. If the prefix "Flt" are stripped, they are:

IsOperationSynchronous
IsIoCanceled
IsVolumeWritable

rather than

OperationIsSynchronous
IoIsCanceled
VolumeIsWritable

Why?

1

There are 1 best solutions below

2
On

contains is the most popular. containsElement could be, and I've never seen doesContainElement. Probably too long.

If you are trying to emulate English, think that bool functions are usually used with if. What sounds better:

    if( a.containsElement(b) )

    if( a.doesContainElement(b) )

    if( a.contains(b) )

? I think 3, then 1, then 2, don't you?