I have a lot of respect for Joël, and wholeheartedly agree that flipping inequalities to remove a negation is a win and that boolean expressions that can be simplified should be simplified (the latter two points of his piece). With that said, I quibble with how helpful it is to reduce the number of negated expressions. Joël offers this example, whilst recommending the version on the left side:

not (a and b) == (not a or not b)

When we talk about the readability of the code, one gut check is to see how easy it is to audibly explain the algorithm to someone else. In everyday speak, if we’re trying to communicate the algorithm above, we’re going to use the version on the right. People are very comfortable communicating that way, even non-programmers talking about everyday decision making. It takes substantially more words to communicate the algorithm in terms of the left version, because first you have to create a mental variable of the result of the parentheses. Even as a developer, the left version is a mild brainteaser for me — it requires more cognitive overhead — whilst the right version is easier to grok.1


  1. My verdict notwithstanding, one caveat comes to mind. I’ve heard of situations, particularly in database queries, where ANDing something has proven substantially less expensive than ORing something. There’s definitely a time and place to flip these things around, but I wouldn’t do it for readability’s sake. In my mind it hurts readability. ↩︎