Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



This is one case where I wish Pascal had won. := for assignment, = for comparison.


Dates back to one of the ALGOL dialects, actually.


Lisps have the distinction between `let` and `set!` which makes the distinction even clearer IMO.


Equals 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.


Not even definition, but "assignment". Definitions do not change.


Sure, but that operation, "assign", takes as its left value a different kind of thing than "relate" or "equate" does.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: