Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

81–90 of 367 posts

Re: Why Does “=” Mean Assignment?

#81
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 ":=".

> "=" was used in Fortran.

And most BASICs, though some (most?) required the keyword LET to introduce an assignment, as well.

Re: Why Does “=” Mean Assignment?

#82
post #23

Is it really worth allowing assignment in places so weird that you also need ==? Wouldn't it be easier to use = for everything and get rid of those weird edge cases?

It does lead to some pretty neat and idiomatic C, if only they just picked a different symbol for assignment.

Re: Why Does “=” Mean Assignment?

#83
post #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).

The article's been updated.

Re: Why Does “=” Mean Assignment?

#85
post #53

Earlier quoted context omitted.

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

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.

Re: Why Does “=” Mean Assignment?

#86
The Go language brings back the ":=" to mean declare and assign, while inferring type.

a := 5

You can also equivalently do

var a = 5

I almost never use the latter within functions (only at module scope).

I believe the former is forbidden except within functions.

Re: Why Does “=” Mean Assignment?

#87

It isn't just mathematically unsound, it's the cause of many errors, especially in C. Certainly a "million dollar mistake". A classic way to guard against accidental use of assignment in logic statements is to write it "backwards", i.e.: if (2 == x) {...} Since (2 = x) won't compile, while (x = 2) will not only compile but might appear to work for a very long time.

https://en.wikipedia.org/wiki/Yoda_conditions

Re: Why Does “=” Mean Assignment?

#88
post #21

Earlier quoted context omitted.

Ditto. Fun fact: various dialects of BASIC let you optionally put LET before your assignment statements. So the following are equivalent: X = 10 LET X = 10

Wait...LET was optional? Auigh! Whole months of my childhood, wasted!

Only tangentially related: an (unsuccessful) search for a genealogy of the Basic programming language led me to https://en.wikipedia.org/wiki/Basic_Using_Reverse_Polish, which led me to http://vintagecomputers.site90.net/comp80/, which has scans of articles giving examples of that language, for example (from http://vintagecomputers.site90.net/comp80/Part_4_Jul_79.pdf):

   018 LET P=P K * B -
and

   135 LET Q=1 F G / 1 - REC 0.00001 * - Q *
but also the sort-of traditional

   016 FOR X=1 STEP 1 UNTIL T
I guess they had a Basic that only allowed expressions with a single operator or a single function call (some early systems with very limited memory did that) to the right of =, and didn’t have the memory for an infix parser.

Re: Why Does “=” Mean Assignment?

#89
post #4

Because programming languages are typically designed for the tiny group of existing programmers than the much larger group of future programmers. The same reason unnecessary tokens exist, and 'drop' means delete in databases. It's entirely cultural.

Technically, DROP is used because DELETE is taken by something that deletes rows and using DELETE for tables and rows is a bit scary so you get DROP. I suspect quite a lot of naming happens that way.

I'd have thought, not being a programmer, that drop was used because whilst the access and relations with the drop-ed table are updated the table isn't necessarily deleted.

Drop updates the logical structure without necessarily acting on the physical storage in a way commensurate with "deletion". You can this drop a million tuple table in a ms (less I expect) whilst deletion would take far, far longer (of the order of a million-times longer).

/guessing

Re: Why Does “=” Mean Assignment?

#90

Pascal got rid of the confusion.. := is assignment = is comparison. I really wish more languages had an specific assignment operator.

I think Pascal got all that from Algol68 (which in turn got stuff from Algol60)

(Pascal is essentially the easy bits to implement from Algol68)

Post reply on HN