3 ms·
You're overcomplicating it, think of it from a math perspective. Don't just look at it as the "assignment operator", look at it as an equals sign. a=b=c=2. T
by acoard 10y ago
You're overcomplicating it, think of it from a math perspective. Don't just look at it as the "assignment operator", look at it as an equals sign.
a=b=c=2. They're all equal, all variables here equal 2.
- simias 10y agoI don't get what maths have to do with it. In maths a = b = 2 is the same as a = (b = 2), (a = b) = 2, (a = b = 2) or a = 2 = b. Clearly it doesn't apply here.
- kupiakos 10y agoIs surrounding an equality with parentheses in math something that is regularly done? When I see (a = b) in math, I don't think of it as "evaluating" to anything like 2+3 would.
- euyyn 10y agoIn math notation I would expect a = (b = c) to mean "a" is a boolean whose value is whether b equals c.
- pyre 10y agoFrom a "math perspective," the equals sign is a statement, not an expression. It is asserting the state of something. In programming, we're not 'stating' that `a = b = c = 2`, we are performing an operation to make it happen. This is why in some early languages the assignment operator was `:=` and the comparison operator was `=`.