Closely related to the previous rule; You don't say "I am not not happy” in English, even if it can be understood with a little effort.  As in English, method names should avoid use of double negatives.

For example, imagine a scenario where a check was needed before every database save to see if it was a permitted user function.

The function call might look like this:

if (!userContext.savingNotPermitted())
{
   // we do the save here
}

However, since the primary activity about to be done is a save, the method should be checking if saving is permitted, as below.

if (userContext.isSavingPermitted())
{
    // we do the save here
}

Tip: Usually the word “Not” does not appear in method names.  If you need to do some logical gymnastics in every call to a method, perhaps it needs to be renamed and reversed to get rid of the “Not”.

blog comments powered by Disqus