DEV Community

Discussion on: Loops are bad, algorithms are good! Aren't they?

Collapse
 
loki profile image
Loki Le DEV

Thanks for this tutorial I totally agree!

This is not related but I noticed you use the not keyword instead of ! for boolean negation,

if (not iCache.read(key, aValue) || expectedValue != aValue) {

Did you know you can also use or, and instead of && , ||.
I find this even more readable and helps avoid confusion with bitwise operators.

Collapse
 
sandordargo profile image
Sandor Dargo

Thanks for your comment, Loik.

You just pointed out that I was inconsistent! It's funny because my only "rule" for the && vs and debate is to follow the conventions of the given codebase.

Though I personally prefer the old way. But it's just personal preference. Good IDEs will warn you on bitwise operators and you can even activate some compiler warning as far as I know.

Sonar, Misra et al. often don't like digraphs/trigraphs and alternative tokens, so whether to use them is also a matter of what rules you try to be compliant with.