7 ms·
Actually, the brunt of the confusion is not the variable, but the '=' sign, which in mathematics means 'is equal to', while in a programming language means 'ass
by zeroxfe 11y ago
Actually, the brunt of the confusion is not the variable, but the '=' sign, which in mathematics means 'is equal to', while in a programming language means 'assign to'. This indirectly changes the semantics of the variable within the statement, and confuses people.
This is why `x + 5 = 10` makes sense in mathematics, but not in a programming language.
- lmm 11y agoThis is one case where I wish Pascal had won. := for assignment, = for comparison.
- vezzy-fnord 11y agoDates back to one of the ALGOL dialects, actually.
- technomancy 11y agoLisps have the distinction between `let` and `set!` which makes the distinction even clearer IMO.
- learnstats2 11y agoEquals sign in mathematics is overloaded: "In mathematics, the equals sign can be used as a simple statement of fact in a specific case (x = 2), or to create definitions (let x = 2), conditional statements (if x = 2, then...), or to express a universal equivalence (x + 1)2 = x2 + 2x + 1." In most programming languages, the equals sign is reserved only for definition. If you wanted to be explicit about this in maths, you can use := and I think that notation would solve a lot of beginner and early programmer problems.
- tel 11y agoNot even definition, but "assignment". Definitions do not change.
- tel 11y agoSure, but that operation, "assign", takes as its left value a different kind of thing than "relate" or "equate" does.