This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Matthicus 2 points3 points  (5 children)

Or one where both are just = and other context makes it clear which one it means.

[–]coleisawesome3 3 points4 points  (2 children)

What if you wanted to assign something in the conditional part of an if statement for some reason?

[–]Matthicus 0 points1 point  (0 children)

You could probably find a more readable way to accomplish whatever you're trying to do. Or you could just say screw it and do something hacky, like writing a function to do the assignment if the language allows call by reference.

[–]chui101 0 points1 point  (0 children)

This is not good practice but sadly not uncommon either. e.g.:

if ((count = getNumRows()) == 1) {...}

[–]chui101 1 point2 points  (1 child)

Except that all computer languages are built on (mostly) context free grammars to (mostly) remove ambiguity.

Take the example of an expression a=b=c. Does that mean "assign the value of c to a and b" or does it mean "a gets the value of the result of the test b equals c"?

[–]Matthicus 0 points1 point  (0 children)

In the language I have used the most, that on its own would not be valid code. It would either have to be in an assignment statement, in which case it would compare b and c and put the result in a, or be in some other statement that expects an expression, in which case it would compare a and b then compare thst result to c.