Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

negated equal vs. not equal

Tags:

coding-style

Lately, I've been reading some code that has

 if (! (a == b) ) 

instead of

 if ( a != b )

in some places.

Obviously these are logically equivalent, but I'm wondering if there is any particular reason to use one over the other.

Are there certain circumstances where one is preferable, or is it all just a matter of personal style?

like image 523
Bill B Avatar asked Nov 28 '22 16:11

Bill B


1 Answers

I really prefer

if ( a != b )

simply because you are supposed to read less and you understand more quickly the message the programmer wanted to transmit.

Remember programmers spend more time reading code than writing it, so the more you can do to make code more understandable, the better.

like image 50
Seb Avatar answered Dec 25 '22 13:12

Seb