DEV Community

Cover image for Code Smell 51 - Double Negatives
Maxi Contieri
Maxi Contieri

Posted on • Updated on • Originally published at

Code Smell 51 - Double Negatives

Not operator is our friend. Not not operator is not our friend


  • Readability


  1. Name your variables, methods and classes with positive names.

Sample Code




This is a semantic smell. We need to detect it on code reviews.

We can tell linters to check for Regular Expressions like !not or !isNot etc as a warning.


  • Readability


Double negation is a very basic rule we learn as junior developers.

There are lots of production systems filled with this smell.

We need to trust our test coverage and make safe renames and other refactors.


More info

Remove Double Negative

Boolean Methods


Photo by Daniel Herron on Unsplash

It’s harder to read code than to write it.

Joel Spolsky

Top comments (5)

arose profile image
Antoine R

Unrelated, but from the title, I thought the article would be about the!! double negation operator, which gives a simple way to check if an integer is non-zero. In C:

return !!myInt; // returns 1 if myInt is non-zero
Enter fullscreen mode Exit fullscreen mode

That's a very basic trick, but I like it :)

mcsee profile image
Maxi Contieri

That is another code smell!!

I will write about it soon

arose profile image
Antoine R

Haha, I have to admit it's not the most readable piece of code :)

Thread Thread
mcsee profile image
Maxi Contieri

Funny thing. You already found out it smells :)

yoursunny profile image
Junxiao Shi

When working with PKI certificates, is it OK to use NotBefore and NotAfter fields, or shall I rename them as AtOrAfter and AtOrBefore?