4 ms·
Most programming languages change the meaning of one of the most common mathematical symbols. There are at least 3 meanings of "X = Y". Pascal: Is X equal to Y
by souprock 8y ago
Most programming languages change the meaning of one of the most common mathematical symbols. There are at least 3 meanings of "X = Y".
Pascal: Is X equal to Y?
C: Change X, making it equal to Y.
Mathematics: X is equal to Y.
Those are all valuable in programming. Normally programmers get the mathematical meaning via a feature such as __assume or __builtin_expect or assert. It can be used for optimization. When the constraint is violated, various bad things can happen. The code can run slower, halt with an error message, or behave in an undefined way.
Every new generation of programmers starts off expecting the mathematical meaning. I don't know of any programming language which uses it. Ideally that would be fixed, but the change might be difficult for the current generation of programmers.
Note that the Pascal meaning can be fairly compatible with the other meanings. The solution is simply to be aware of context. On a line by itself, X=Y makes no sense as an equality test. Within the controlling part of an "if" or loop, assignment need not be supported. That does the job. Alternately, the meaning could change by having a keyword in front for assignment ("let" is popular) and/or for the assertion. So we could distinguish all three meanings with syntax like "if X=Y", "let X=Y", and "assume X=Y".