Give Boolean variables and functions positive names. Avoid both - direct negation (“NOT something”) and words which carry a tinge of negativity (like “disabled” instead of “enabled”).
Think positively! That will simplify reading and understanding of Boolean expressions, especially if they are nested.
For example, compare the expressions if !DocNotPrinted() and if DocPrinted(): they are logically equivalent, but the positive version is easier to understand. As you see, the difference appears even when the expressions are stand-alone, but imagine if they would be a part of a complex Boolean expression! You can contradict: and what if the calling code wants to ask if the document has not been printed yet? Whether if !DocPrinted() is better than if DocNotPrinted()? Ok, we always have a chance that our Boolean var or method will be used with NOT, but using of positive wording will cause maximum ONE negation in that situation, while using negative wording can result in TWO of them - "negation of negation"!
Negative words are not as problematic as the direct negation, but it’s better to avoid them too. The following lists contain a few examples of "negative" and "positive" words
NEGATIVE WORDS (TO AVOID): disabled, disallowed(prohibited), hidden, excluded, failed.
POSITIVE WORDS (TO USE INSTEAD): enabled, allowed, displayed, included, ok(succeeded).
Here we discuss only Boolean names. Of course, if your non-Boolean function performs a negative action, its name should reflect exactly that action, for example: DisableSaveButton, ProhibitPrinting, ExcludeExpiredRecords.
- Site Admin
- Posts: 111
- Joined: 19 Feb 2013, 20:33
Return to Intriguing World of Logic
Who is online
Users browsing this forum: No registered users and 1 guest