More accurately, in Python it would be:
if x = 3: # x is assigned 3 and then tested
do_something_here()
This is different from: if x == 3: # x is compared to 3
do_something_here()
Very clear difference between the two statements.What if we want to assign and then compare?
if (x = 3) == y:
do_something_here()
or... if x = 3; x == y: #Python evaluates left to right...
do_something_here()
In fact, you could... if x = 3; x == y; x = x + 1: #Python evaluates left to right...
do_something_here()
Not super elegant, but it makes sense. I wouldn't want to write code like that in any language unless it was very well justified.What if we want to compare and then assign?
if x == y; x = 3: #Python evaluates left to right...
do_something_here()
Side note: Why, oh why, don't we have pre and post increment/decrement (++/--) in Python? Another religious decision.I guess I am having trouble seeing where this ambiguity might be. What is ambiguous about usage that is currently not legal and is later defined as a new way to make assignments?
In other words, nobody is using it that way today because it doesn't work. Tomorrow we say: From now on, you can make assignments inside of several conditional statements.
What's ambiguous about that?
This isn't foreign at all, is it? I mean, we have been able to do this in C for decades:
int i;
for(i=1; i<=3; i++)
{
printf("%d\n", i);
}
In fact, you can do this: int i;
for(i=1; i<=3; i=i+1)
{
printf("%d\n", i);
}
That's TWO assignments, not just one. No special operator or syntax. Last I checked no airplanes have crashed, MRI machines stopped working and nobody died because of this. Forgive me but, I just don't see the ambiguity at all. Once you define the extension of functionality the rest is not a problem.That said, I am eager to learn. I've only been designing hardware and software since about 1982 or so and have programmed in nearly every mainstream language in existence on platforms ranging from embedded to Silicon Graphics supercomputers and even the web. It is quite possible I am confused or just don't understand something. I do have a very pragmatic view of this stuff. By which I mean to say: Simple is usually better and there has to be a very, very good reason to reinvent any wheel.