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?
containsis the most popular.containsElementcould be, and I've never seendoesContainElement. Probably too long.If you are trying to emulate English, think that
boolfunctions are usually used withif. What sounds better:? I think 3, then 1, then 2, don't you?