Conditionals often include short circuit operators. So, given this example:
if ( a=func(x) && b=func(y) )
{
// do this
}
It may not be immediately obvious, but the second assignment would only occur if the first returned >0
, and if func(y)
had other side effects that you were expecting, they would not happen either.
In short, if you know what you are doing and understand the side effects, then there is nothing wrong with it. However, you must consider the possibility that someone else may be maintaining your code when you're gone and they might not be as experienced as you.
Also, future maintainers may think you intended the following:
if ( a==func(x) && b==func(y) ) ...
If they "fix" your code, they actually break it.
=
and==
is so big your tests should fail. (unlike==
vs===
- I'd like my IDE to warn about that, preferably)