In c++, if
func
returns a value intepretable as bool (eg
std::optional<T>
), I do like going...
Code:
if(auto x = func()) {
doSomething(*x);
}
Now what Javascript does with
==
is a true abomination. So much so they had to invent
===
to get around it.
I once spent a day debugging some code with a colleague only to find a typo in a C++ if statement caused it all. Something along the lines of...
Code:
if (condition1 && condition2 || !!condition3) {
}
Drove us nuts, we just couldn't see the '!!' typo for ages. I now use the C++ keyword*
not
instead of '!'. Also 'and' and 'or', makes for nicer looking code IMHO.
*Those are infact keyworks in the language, but people don't use them.