I bet this is an old topic and there are lots of opinions on the subject. But I can't tell you how many times I've inadvertently typed "if (x=y)" when I meant "if (x==y)" and then wasted time trying to figure out what was wrong until I spotted this typo. I can only imagine how many beginners get nailed by this over and over.
Of if we don't like warnings, another suggestion would be a compiler switch that by default doesn't allow a single = in an "if" unless you override the switch. Only experienced programmers are going to demand assignment within an "if" anyway and this surely seems like something where we're unnecessarily burdening newbies.
All programming languages are slightly different, I'm not sure it's worth changing everything so it's more familiar with something else.
In pascal, for example, = is the comparison and := sets the variable.
What'd be nice is if the IDE could translate the code from mimicing one language into arduino-suitable code. So you could set it to c++ syntax, or php syntax and it'd sort it back into arduino syntax.
The lack of $ on variables gets me every time I'd doing any development involving php and the arduino, though that's more missing them off in php and wondering why nothing's working.
You can swap operands in comparison, like if( 4 == x ... I know several people writing like that. If you make a mistake and type 4 = x you'll receive an error from the compiler.
You can only use a single = sign if there is an object that returns a Boolean value can't you? Paraphrasing ftw. You realise if we had a full IDE this would be pointed out to us... Cough cough visual studio...
You can only use a single = sign if there is an object that returns a Boolean value can't you?
No. Boolean means 0 or 1, it actually looks whether the value is 0, if it is, it returns false, otherwise true*. The caveat of this is that it accepts lots of values as true, and only 0 as false. So '0 or 1' is actually incorrect.. from a technical standpoint, logic wise, it holds up ('unset' or 'set').
Also, you can simply use a boolean operator on the returned value, the returned value will be stored and then checked against the boolean operator (make sure to use brackets around the value assignment, or it'll do the boolean operation first.. which is also a perfectly legit use).
If visual studio whines about an assignment in an if, I'll never touch visual studio again. It is perfectly valid coding.. can make reading certain complex control structures readable too.
when testing this, you can't test it like this:
if(100 == true)
Because, 100 doesn't equate to the 1 that the true constant has been defined as, instead you should test it like this:
if(100)
This one will pass the check, and execute the body of the if, if a value of 0 is used in the if statement, it won't execute the body.