I hit this problem with C & C .
When we are comparing 2 things.
The order of appearance does not matter to the language Compiler or Interpreter.
But Assignment takes the value on the right side and changes the left side value.
The form you use is very commonly used.
if ( variable == constant )
But as you found, programming languages sometimes have side effects.
In this case there was a sort of hidden convention that if an Assignment was successful inside an if, the result is true.
And most programming languages implement true as 1
The Comparison became a constant expression
if ( 1 )
because of a hidden extra step from unexpected Assignment.
Suggestions:
Very first thing to check is Warnings from build tools you use.
Lint utilities may help with this.
Coding standards for the project may also help.
Using Lint sometimes leads to better standards.
What I do:
if ( constant == variable )
Seems backwards as far as expressing the Comparisons.
But this form eliminates the possibility of accidental Assignment.
Because
if ( true = isValidUser )
Assignment becomes logical nonsense, constants can not be changed.
Practically every programming language will show an Error.
AI may also help but it adds a dependency on a complex tool.
Hope this helps, :)
P.S.
if ( true == usingPython )
{
neverMix ( Tabs & Spaces );
}
else
{
confusionForMe = 1.5 Days;
}