Hacker News new | ask | show | jobs
by int_19h 3596 days ago
There are many languages that use = for assignment and == for comparison, without the possibility of confusing the two. In Python, for example, assignment is not an operator at all, so using it in expression context is invalid.

Which leaves the distinction between assignment and comparison - which is always there - as the only reason to have two distinct operators. Which ones they are becomes a matter of taste, but as I recall, the reason why C settled on = for assignment is because it's that much more common. This is still the case today, even in pure languages where it's used for bindings only.

2 comments

Well, in lisp making assignment a statement is a non-option: statements don't exist. The closest thing is returning #<unspecified> in scheme.
Well, it's similar to math and that was there long before lisp or C
Math notation uses := for assignment and = for equality, no? So in that sense Algol and the Pascal family are more consistent with that, while C actually diverged.
Depends on your field. Some math subjects would argue that "assignment" does not exist, because the same name within the same scope always refers to the same value, whether it's known or not.

Within algorithms, I'm most used to "<-" for assignment, for example "i <- i + 1" inside a loop to count iterations.