Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

11–20 of 367 posts

Re: Why Does “=” Mean Assignment?

#11

Bcpl still exists in 2018?

It does! Even though, Martin Richards' homepage [0] hasn't been updated in a while you can try it out with a small amount of fuss [1].

0: http://www.cl.cam.ac.uk/~mr10/

1: https://gist.github.com/seaneshbaugh/e09abd748ccc07c5463f253....

Re: Why Does “=” Mean Assignment?

#13
Another interesting way to think about it is as "match". That is try to match the stuff on the right with the stuff on the left.

Take Erlang for example:

    1> X = 1.
    1
    2> X = 2.
    ** exception error: no match of right hand side value 2
Notice variables are immutable (not just values themselves). Once X becomes 1, it can only match with 1 after that. You might think this is silly or annoying, why not just allow reassignment and instead have to sprinkle X1, X2 everywhere. But it turns out is can be nice because it makes state updates very explicit. In complicated applications that helps understand what is happening. And it behaves like you'd expect in math, in the sense that X = X + 1 doesn't make sense here either:

    1> X = 1.
    1
    2> X = X + 1.
    ** exception error: no match of right hand side value 2
    3>    
It does pattern matching very well too, that is, it matches based on the shape of data:

    1> {X,Y} = {1,2}.
    {1,2}
    2> X.
    1
    3> Y.
    2
    4>
In other languages we might say we have assignment and destructuring but here it is rather simple it's just pattern matching.

Re: Why Does “=” Mean Assignment?

#14
> Since assignment is about twice as frequent as equality testing in typical programs, it’s appropriate that the operator be half as long.

Ken Thompson on why '=' is assignment and '==' the equality check.

It's this kind of mindset that puts me off Go. But I can totally see that many who want a better C getting into Go exactly for reasons like this.

Re: Why Does “=” Mean Assignment?

#15
The length of symbols should roughly be negatively correlated with its frequency.

Since in procedural language, assignment is a much more common operation than equality check, it is reasonable to favor "=" over ":=" or even "<-".

Re: Why Does “=” Mean Assignment?

#16
I don't understand the LISP line at all. I would have said "LET", "SET", and "EQUAL" (since it's talking about numbers). Is there something I'm missing?

EDIT: It's since been changed to "let", "set", "equal" (but still lower-case).

Re: Why Does “=” Mean Assignment?

#17
post #5

Because K&R had terrible keyboards so they abbreviated everything as much as possible. Traditionally := was used for assignment, which makes sense since it is an asymmetric symbol for an asymmetric operation.

Traditionally? I don't think there was a "tradition". ":=" was used in Algol. "=" was used in Fortran. COBOL didn't use either "=" or ":=".
Post reply on HN