Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

261–270 of 367 posts

Re: Why Does “=” Mean Assignment?

#261
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.

The use of = for assignment goes back to Heinz Rutishauser's Suplerplan from 1951, and it was adopted by Fortran.

Rutishauser might have gotten it from Konrad Zuse's Plankalkül, which used the right double arrow ⇒, which looks a little like =.

Plankalkül had the order and the assignment reversed relative to C, so to increment a variable Z1, you'd write:

    | Z + 1 ⇒ Z
  V | 1       1
  S | 1·n 1·n 1·n
(The first line is the 'main line'; Z stands for Zwischenwert, i.e. "intermediate value". The second line is the 'value line', which contains the indices of the variables -- to store Z1 + 1 in a new variable Z2, you'd replace the second 1 with 2. The third line contains Struktur-Indizes.)

Re: Why Does “=” Mean Assignment?

#262
post #252
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.

I think the simple reason is that two characters are harder to type then one character, if they both are a key combo. And to keep syntax more clean.

Yeah but this introduced an easy path for errors. You could mean to write `==` and instead write `=` and it'll work fine in C in practically all locations (even as conditions of if-statements). Using `:=` could have likely alleviated this error to a noticeable degree, if not entirely.

Re: Why Does “=” Mean Assignment?

#263

because in math it means assignment. y = mx+b That is an assignment. There is also a math symbol that specifically designates equivalence.

‘=‘ does not mean assignment in math.

Your example

  y = mx + b
could equivalently be stated as

  y - b = mx
What does it mean to assign something to ‘y - b’?

Another example,

  2 = x 
means exactly the same thing as

  x = 2
What does it mean in your semantics to assign x to 2?

Re: Why Does “=” Mean Assignment?

#264
post #53

Earlier quoted context omitted.

FORTRAN was far from the first high level language. Plankalkül for example was out a decade earlier and used →. EX: P1 max3 (V0[:8.0],V1[:8.0],V2[:8.0]) → R0[:8.0] https://en.wikipedia.org/wiki/Plankalk%C3%BCl So, there really was a lot of languages out there, but := was fairly common because it was easy to parse and type.

It didn't actually contribute much to the evolution of other languages though, right? Had anyone even heard of it when Fortran/ALGOL/etc were being designed?

Zuse seems to have been under the impression that some of the ALGOL designers were aware of it: https://books.google.com/books?id=AsvSBQAAQBAJ&pg=PA522&lpg=...

Rutishauser was, at least.

Re: Why Does “=” Mean Assignment?

#265
post #144

Earlier quoted context omitted.

I sympathize with this view; I did some simple programming in C-like languages before I learned algebra, and it's sometimes hard to not see = this way. But if = in math notation denoted "assignment", what could ≠ mean?

Maybe lhs = rhs is the set of assignments implied by a postcondition. So x = 5 implies a single assignment, but x = ±5 could mean two possible assignments. Similarly, x ≠ 5 would mean all the possible assignments but x = 5.

Equality is symmetric. If lhs = rhs then rhs = lhs. x ≠ 5 means exactly that, x is anything that is not 5. So if you are talking about the natural numbers, x could be any element of the set {0, 1, 2, 3, 4, 6, 7, ...}. If x = ±5 then x could be any element of the set {-5, 5}.

Re: Why Does “=” Mean Assignment?

#267
post #261

Earlier quoted context omitted.

The use of = for assignment goes back to Heinz Rutishauser's Suplerplan from 1951, and it was adopted by Fortran.

Rutishauser might have gotten it from Konrad Zuse's Plankalkül, which used the right double arrow ⇒, which looks a little like =. Plankalkül had the order and the assignment reversed relative to C, so to increment a variable Z1, you'd write: | Z + 1 ⇒ Z V | 1 1 S | 1·n 1·n 1·n (The first line is the 'main line'; Z stands for Zwischenwert, i.e. "intermediate value". The second line is the 'value line', which contains…

What are Strukturindizes?

Re: Why Does “=” Mean Assignment?

#268
post #53

Earlier quoted context omitted.

FORTRAN was far from the first high level language. Plankalkül for example was out a decade earlier and used →. EX: P1 max3 (V0[:8.0],V1[:8.0],V2[:8.0]) → R0[:8.0] https://en.wikipedia.org/wiki/Plankalk%C3%BCl So, there really was a lot of languages out there, but := was fairly common because it was easy to parse and type.

Plankalkül had the advantage of not having to run on a real machine. As far as := is concerned having to use the shift key for an assignment is less than ideal but there really aren't any better options on a modern keyboard. I think C's use of = is a bit braindamaged but it is nice and quick to type.

On an ASR33 = is the character you have press shift for. : is unshifted.

Re: Why Does “=” Mean Assignment?

#269

Earlier quoted context omitted.

> "=" was used in Fortran. And most BASICs, though some (most?) required the keyword LET to introduce an assignment, as well.

Let became optional quickly it seems But most BASIC versions would accept 'let a = 1' Personally, I don't see why the big fuss. If your assignment and comparison operators are the same the only thing you lose is doing x = (y == 2); kind of expressions (since you would disambiguate from conditional expressions). Now, assignments are done more frequently than comparisons, hence why it makes sense for it to be the simpl…

You wouldn't even lose that if you can accept that assignments can't be expressions, which seems like a bit less of a loss.
Post reply on HN