Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

221–230 of 367 posts

Re: Why Does “=” Mean Assignment?

#221

Earlier quoted context omitted.

I really like this about pascal. We read it out loud as "becomes the same as", this being what was actually happening. I've carried the habit over to C despite the bare =, it helps me reason and seems to aid in preventing the =/== error.

The shorthand I use for "becomes the same as" is "gets".

My CS professor (~ola) taught it as "gets" and to this day when I talk out code people get confused. I'll say, "x gets 3" and they look at me funny. But I find it helpful for differing between assignment and equality.

Re: Why Does “=” Mean Assignment?

#222

Earlier quoted context omitted.

I really like this about pascal. We read it out loud as "becomes the same as", this being what was actually happening. I've carried the habit over to C despite the bare =, it helps me reason and seems to aid in preventing the =/== error.

The shorthand I use for "becomes the same as" is "gets".

I never liked the 'gets':

"x gets 7" is fine but

"x becomes the same as y" seems better than "x gets y"

Re: Why Does “=” Mean Assignment?

#223
post #164
post #161

= has contextual meaning in math, why not programming? It's not like we can fool ourselves into thinking that tests for equality don't also have wildly different meaning depending on context. No operator has a universal meaning, nor should they.

Can you provide an example where equals sign is not equality I'm curious.

How about Σ Sigma notation for summation? It's often written with something like i=1 at the bottom and 1000 at the top to denote the summation from 1 to 1000. The Wikipedia article at https://en.wikipedia.org/wiki/Summation has some examples.

Re: Why Does “=” Mean Assignment?

#224
post #143
post #26

Earlier quoted context omitted.

From the article: > Looking at this as a whole, = was never “the natural choice” the assignment operator. Pretty much everybody used := for assignment instead, possibly because = was so associated with equality. Nowadays most languages use = entirely because C uses it, and we can trace C using it to CPL being such a clusterfuck.

> From the article: Articles, like desserts, aren't always right. I am sorely tempted to pull out Sammet's book tonight and start counting.

Too late to edit, but I've gone and done it: scanned through Sammet's Programming Languages: History and Fundamentals for languages with identifiable assignment statements. I skip assembly-style, English-like (COBOL etc.), and functional-style (LISP etc.) syntax, and for summary purposes ignore accompanying keywords like BASIC's LET.

Results:

ν = ε     18 (AMTRAN, BASIC, COLASL, CPS, FORTRAN, FORTRANSIT, JOSS, JOVIAL, Klerer-May, Laning & Zierler, MAD, MADCAP, MAP, MATH-MATIC, MIRFAC, PL/I, QUICKTRAN, UNICODE)

ν ← ε     4 (APL, DIALOG, IT, LISP2)

ε → ν     2 (MADCAP, NELIAC)

ν := ε     1 (ALGOL)

ε * ν     1 (BACIAC)

So pretty much everybody used ‘=’. ALGOL was an outlier, though admittedly more influential than BACIAC.

Re: Why Does “=” Mean Assignment?

#225
post #128
post #40

Earlier quoted context omitted.

Fun fact, R also has -> (assign to the RHS instead of LHS), and "super-assignment" >, and also can use = sometimes too (and I think has different semantics). Yay R.

I write R daily and have always used = for convenience. I can count on 0 hands how many times that has affected me. <<- has its uses though!

FWIW, that's what Ross Ihaka does as well (or at least did in a presentation that I watched - and pointed out that you can use = for assignment). Personally, I think = for assignment is a disaster, and wish I could use in every language.

Re: Why Does “=” Mean Assignment?

#227

I think they are forgetting that a lot of languages take que's from old math textbooks where you would see function definitions written as "f(x) = nx + b" or "y = nx + b" and constant assignment with a "c = " notation. if you want to calculate the output of a function into a data table(which is what early computers were often doing) iterating a variable x over a f(x) = xn + b(with n and b being fixed constants) is ex…

_old_ math textbooks? Have they changed this in new ones?

Saying something is old implies that it has been the case for a long time, not that it has necessarily changed recently.

Re: Why Does “=” Mean Assignment?

#228
"I don’t know if this adds anything to the conversation. I just like software history."

This topic has my curiosity peaked as well. What is a good place to start reading/understanding more about this?

From my understanding software development is a complex field that blew up in multiple places at the same time.

Re: Why Does “=” Mean Assignment?

#229

In R, it is actually distinguished that way, example: a a + 1 -> a # also works, but REALLY bad practice But, so does a = a + 1 Granted, there are a bunch of R haters (especially from people with formal CS educations), I think this convention makes a lot of sense. While most will disagree about the ' In case you are wondering, the difference between foo(x = 'value') x is declared in the scope of the function, whereas…

> Granted, there are a bunch of R haters (especially from people with formal CS educations), I think this convention makes a lot of sense.

To be clear, the assignment syntax is great, it's other things that are the target of R haters' hate! Like a high-level language without hash tables.

Post reply on HN