Blogify

Blogify

javascript

Stop using double negatives or nobody will understand your code

Volodymyr

Volodymyr

Post

This is a big mistake many developers make that makes code cryptic and unreadable.

❌Don’t do this:

Double negatives like this makes it much harder to think about the logic and conditionals in your code.

It’s much better to name them positively:

There is no indirection and your brain takes zero time to parse this.

Just imagine the pain of trying to understand this:

I didn’t not forget about not being unable to use the account.

Lol I couldn’t even understand it myself for a while even though I made it up.

Compare to the far more natural way you’d expect from a sensible human:

I remembered that I could use the account.

Control flow negation

This is a more delicate form of double negation you need to know about: