Using a count() function and testing for zero:
bottle.count("alcohol") == 0
versus
bottle.notContains("alcohol")
It is not only shorter (by one character) while producing a more general result, but also avoids boilerplate at the start of the function name which has to be typed before your editor can begin offering sensible choices.
You will say of course that counting all the alcohol molecules in a bottle to find out if it contains just one such molecule is rather a waste of time, but this means that you lack faith in your compiler to detect this optimization opportunity for you.
Conversely, if you possess a device that can individuate a single molecule of alcohol then it is time to give up programming and switch to extracting gold from seawater.
NotContains
implies two operations: 1) checking whether the object contains something, and 2) a boolean "not". If the caller needs to negate it, he will.IsEnabled
is preferred toIsDisabled
, andIsValid
is preferred toIsInvalid
as well. There are exceptions where the negative function name is fundamentally relevant to the operation, likeIsBlacklisted
. I would suggest you just stick withContains()
.