dilluns, 26 de maig del 2014

Double negative

What does this mean?
No digit characters are rejected by NumericalValidator.

Even though the quite self-descriptive NumericalValidator class name, it is unclear if the validator accepts or rejects letters or digits. This sentence is hard to understand due to the double negation, which requests an unnecessary effort from the reader (as it has to inverse the content of the sentence twice to find out the real meaning).

In a nutshell, do not ever use double negative, it's misleading and error prone.

Another classical example
I do not disagree can be translated into I agree.

The exception
Apart of poetry, the only exception I can see to this rule is when you pretend to confuse your reader or whoever are you arguing with, then it can be used as a way to obscure the message (and without lying!).
I wouldn't recommend you to do so, discussions which need treats like those are usually unhealthy as they derive in who's best at using the language and rhetorics and not at what's the best solution to the subject being discussed.

The code!
Of course, all this dissertation also applies to your code! Avoid using the negation operator in front of variables whose name is negative (either contain not in the name or use a negative word).

For example: 
!notClosed would be the same as !Open but less readable.

Cap comentari:

Publica un comentari a l'entrada