News for hackers. Stuff that matters.
Re:Why Does “=” Mean Assignment? by User23 on Tuesday April 10, 2018 @03:42PM (#16804529)
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.

Re:Why Does “=” Mean Assignment? by kps on Tuesday April 10, 2018 @05:32PM (#16805663)
Granted they had some bad keyboards; there's a oft-reproduced photo of Thompson & Ritchie at Teletype 33s, but those had '63 ASCII, including ←.

Probably more important is that the Unix/C developers came from Multics, written in PL/I, which (following Fortran) used ‘=’ for assignment. And Fortran was still important; Unix had a Fortran compiler at least as far back as Second Edition, when C was being born. Kernighan & Plauger's Elements of Programming Style used Fortran and PL/I for its examples, and Software Tools used Ratfor. ‘=’ is simply what they were used to.

Re:Why Does “=” Mean Assignment? by cwzwarich on Tuesday April 10, 2018 @04:05PM (#16804786)
The use of = for assignment goes back to Heinz Rutishauser's Suplerplan from 1951, and it was adopted by Fortran.
Re:Why Does “=” Mean Assignment? by 80386 on Wednesday April 11, 2018 @02:36AM (#16808590)
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? by wiz21c on Wednesday April 11, 2018 @07:18AM (#16809950)
The discussion here show how much computer languages are human's work, with all humans' little approximations, taste, creativity, etc. Great read :-)
Re:Why Does “=” Mean Assignment? by taejo on Wednesday April 11, 2018 @03:38AM (#16808871)
What are Strukturindizes?
Re:Why Does “=” Mean Assignment? by exceptione on Wednesday April 11, 2018 @05:30AM (#16809381)
The translation would be structure indexes.
Re:Why Does “=” Mean Assignment? by taejo on Wednesday April 11, 2018 @08:35AM (#16810435)
Yeah, I think that would be clear even if I didn't speak German, which I do. I'm curious what their semantics are / what they're for.
Re:Why Does “=” Mean Assignment? by 80386 on Wednesday April 11, 2018 @05:12PM (#16815707)
Bauer and Woessner [1] weren't very clear on their semantics, but according to Bruines [2], they're type annotations.

[1] https://web.archive.org/web/20090220012346/http://delivery.a...

[2] http://www.cs.ru.nl/bachelorscripties/2010/Bram_Bruines___02...

Re:Why Does “=” Mean Assignment? by jghn on Tuesday April 10, 2018 @03:51PM (#16804632)
There’s also <-, most commonly seen in R but draws it’s heritage from the APL keyboard
Re:Why Does “=” Mean Assignment? by nfoz on Tuesday April 10, 2018 @04:18PM (#16804907)
Fun fact, R also has -> (assign to the RHS instead of LHS), and "super-assignment" <<- and ->>, and also can use = sometimes too (and I think has different semantics). Yay R.
Re:Why Does “=” Mean Assignment? by klmr on Wednesday April 11, 2018 @09:47AM (#16810986)
> also can use = sometimes too (and I think has different semantics)

That’s a common misconception (even the official documentation is misleading).

In reality, assignment `<-` and assignment `=` have the exact same semantics (except for precedence, and unless you redefine them, which you can). The confusion comes from the fact that the `=` symbol is syntactically overloaded: it is also used for named argument passing (`foo(x = 1)`). This leads people to falsely claim that, if you wanted to perform assignment in a function call (which occasionally makes sense in R), then you’d have to use `<-`. But this is false. You merely need to disambiguate the usage, e.g. with extra parentheses: `foo((x = 1))` works.

Re:Why Does “=” Mean Assignment? by nfoz on Wednesday April 11, 2018 @10:05AM (#16811166)
That's a fantastic clarification, thanks for that!
Re:Why Does “=” Mean Assignment? by bllguo on Tuesday April 10, 2018 @05:26PM (#16805614)
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!
Re:Why Does “=” Mean Assignment? by bachmeier on Tuesday April 10, 2018 @10:48PM (#16807650)
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 <- and -> in every language.
Re:Why Does “=” Mean Assignment? by neuxenian on Wednesday April 11, 2018 @10:18AM (#16811294)
I've used R since it was in beta form, and one of the most interesting things to me (aside from the evolution of type hierarchy) has been changes in use of the assignment operator.

When I started, = was the norm for assignment, with == for evaluating equality. Later I started noticing that people were recommending <- based on scope concerns, but it was kind of subjective preference. Now I see articles like this saying that the "preferred use" is <-, and some people don't even know about =.

I agree = versus == can lead to tricky errors in code, but I still prefer = for various reasons in general in languages (although I get the scope arguments).

The reason is that = is shorter, and assignment is an definitional equality, which to my impression is the whole point of programming in general usually. As others have suggested here, between = and ==, = is by far the more commonly used operator in meaning, so to me it makes sense to use = for succinctness.

In math, there is an "equal by definition" operator, with three lines, so I could see that, but keyboards don't have that, so it's more steps. := is also a kind of standard "by definition" usage as discussed in the article, but again, it's more steps. I'd still prefer that over <- in R.

Re:Why Does “=” Mean Assignment? by jghn on Wednesday April 11, 2018 @11:22AM (#16812038)
Interesting. I started using it in 2000 and was working directly with members of R-core at the time. My experience was that the only time I ever saw = used was by DTL.

It really wasn’t until Google published their style guide and then later when Hadley published his that I started seeing = in heavy usage.

To your point about = being shorter I wonder if the difference was that a lot of the folks I interacted with were using Emacs with ESS which would interpolate _ to <- so they wouldn’t have noticed? Just a theory.

Either way I was taught from some of the R creators that <- was evil and to be avoided. It wasn’t until I stopped using R regularly that I switched, it became too mentally taxing to change assignment operators when I bounced between languages

Re:Why Does “=” Mean Assignment? by bachmeier on Wednesday April 11, 2018 @12:04PM (#16812505)
I teach R, and most of the students have never programmed before, at least not anything other than having been exposed to a configuration file or writing a little html.

x = x+1 is really confusing because of the way kids learn math. The notation x <- x+1 at least conveys the idea of taking a value and storing it somewhere.

Re:Why Does “=” Mean Assignment? by jghn on Wednesday April 11, 2018 @07:23AM (#16809993)
I find -> to be useful when poking around in the REPL but IMO it should never be used in real code.

I spent some time as a package author, that’s where I found <<- to be the most useful

Re:Why Does “=” Mean Assignment? by kbp on Tuesday April 10, 2018 @06:01PM (#16805934)
In the original Smalltalk implementation, the character corresponding to _ in ASCII was a left facing arrow, which Smalltalk used for assignment at the time.
Re:Why Does “=” Mean Assignment? by bogomipz on Wednesday April 11, 2018 @07:09AM (#16809872)
I'm not following. The corresponding ASCII code for _ is 96 no?

http://www.theasciicode.com.ar/extended-ascii-code/underline...

Re:Why Does “=” Mean Assignment? by tom_mellior on Wednesday April 11, 2018 @07:41AM (#16810112)
"In the original Parc Place image, the glyph of the underscore character (_) appeared as a left-facing arrow (like in the 1963 version of the ASCII code). Smalltalk originally accepted this left-arrow as the only assignment operator. Some modern code still contains what appear to be underscores acting as assignments, hearkening back to this original usage. Most modern Smalltalk implementations accept either the underscore or the colon-equals syntax."

https://en.wikipedia.org/wiki/Smalltalk#Assignment

Re:Why Does “=” Mean Assignment? by kps on Wednesday April 11, 2018 @10:28AM (#16811389)
Pre-1967 ASCII had slightly different printable characters and somewhat different control characters. See e.g. https://en.wikipedia.org/wiki/ASCII
Re:Why Does “=” Mean Assignment? by classichasclass on Wednesday April 11, 2018 @01:34AM (#16808329)
And now you know where the left-arrow on Commodore keyboards came from (same ASCII value): ASCII-1963, which became PETSCII instead of ASCII-1967.
Re:Why Does “=” Mean Assignment? by blattimwind on Tuesday April 10, 2018 @04:53PM (#16805266)
Common in Pre-Python pseudo code and algorithms.
Re:Why Does “=” Mean Assignment? by davvolun on Tuesday April 10, 2018 @05:14PM (#16805501)
Are you making an argument that Python has caused us all to start writing pseudo-code using `=` for assignment?
Re:Why Does “=” Mean Assignment? by chocolatebunny on Tuesday April 10, 2018 @07:43PM (#16806744)
I think he's making the argument that when we write "pseudo-code" these days we're just writing python
Re:Why Does “=” Mean Assignment? by kccqzy on Tuesday April 10, 2018 @05:38PM (#16805714)
When I write pseudo code I still use <- for assignment (or a \leftarrow in LaTeX), despite being fluent in Python now. I guess old habits die hard.
Re:Why Does “=” Mean Assignment? by ddp on Tuesday April 10, 2018 @06:23PM (#16806121)
The point is that ':=' evolved in Algol 68 to solve the ambiguity inherent in '='. C is simply from a less thoughtful and primitive language family and modern languages still seem to be copying C's horrible syntax. It's also probably why technical papers are written in Algol-like pseudocode using the '<-' symbol in LaTeX for assignment.
Re:Why Does “=” Mean Assignment? by jjgreen on Wednesday April 11, 2018 @05:10AM (#16809307)
The syntax of C is a thing of beauty. The decision to use = for assignment and == for equality was natural, since assignment is more common than equality testing; similarly, articles are usually short words in natural languages. Algol 68 and Pascal got this wrong, and where are they now?
Re:Why Does “=” Mean Assignment? by caf on Wednesday April 11, 2018 @09:08AM (#16810702)
Pascal got a new name and career as PL/SQL ;)
Re:Why Does “=” Mean Assignment? by tnecniv on Wednesday April 11, 2018 @12:18AM (#16807995)
Technical papers are written using '<-' in pseudocode because the papers likely use '=' elsewhere to assert equality in a mathematical statement and they want to avoid confusion.
Re:Why Does “=” Mean Assignment? by goatlover on Wednesday April 11, 2018 @12:25AM (#16808026)
> avoid confusion

You’re kind of making the parent’s point.

Re:Why Does “=” Mean Assignment? by tnecniv on Wednesday April 11, 2018 @01:24AM (#16808290)
Yes, although my intention was to further support their last statement which was left open to a degree.

There is a slight distinction. If you are creating a programming language, you can come up with whatever syntax you'd like for assignment and the user has to learn it. Some choices are better than others if you want your language to be used, but there is a specification for the language that you have written down, either as a human readable document or as the compiler/interpreter. With pseudocode in technical documents, the author typically lacks the space, time, and interest to generate such a specification and leans on mathematical notation to keep things precise.

Re:Why Does “=” Mean Assignment? by bonesss on Wednesday April 11, 2018 @05:46AM (#16809489)
"<-" is used for assignment in F#, though variable binding is "=", so:

    let mutable x = 4   // x is equal to 4
    x <- 7              // x is equal to 7
Re:Why Does “=” Mean Assignment? by noonespecial on Tuesday April 10, 2018 @06:17PM (#16806063)
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.

Re:Why Does “=” Mean Assignment? by mturmon on Tuesday April 10, 2018 @06:38PM (#16806230)
The shorthand I use for "becomes the same as" is "gets".
Re:Why Does “=” Mean Assignment? by ivyirwin on Tuesday April 10, 2018 @10:10PM (#16807507)
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? by noonespecial on Tuesday April 10, 2018 @10:26PM (#16807560)
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? by gowld on Wednesday April 11, 2018 @12:51AM (#16808132)
that's wrong, though. x becomes a copy of y, which is only transiently the same.
Re:Why Does “=” Mean Assignment? by dmichulke on Wednesday April 11, 2018 @05:37AM (#16809440)
What is "transiently the same"?

Genuinely asking - my first thoughts are:

"transiently the same" is not the same as "the same", hence it is not "the same", and therefore "not the same".

No jokes on the meta-level please :o)

Re:Why Does “=” Mean Assignment? by Y_Y on Wednesday April 11, 2018 @06:29AM (#16809676)
Depends on the language, and the types of x and y. See e.g. python.
Re:Why Does “=” Mean Assignment? by efitz on Tuesday April 10, 2018 @09:05PM (#16807198)
I was taught to read it as “takes the value of”.
Re:Why Does “=” Mean Assignment? by AnimalMuppet on Tuesday April 10, 2018 @03:57PM (#16804695)
Traditionally? I don't think there was a "tradition". ":=" was used in Algol. "=" was used in Fortran. COBOL didn't use either "=" or ":=".
Re:Why Does “=” Mean Assignment? by Retric on Tuesday April 10, 2018 @04:30PM (#16805012)
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.

Re:Why Does “=” Mean Assignment? by jandrese on Tuesday April 10, 2018 @04:57PM (#16805336)
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? by aap_ on Wednesday April 11, 2018 @03:53AM (#16808938)
On an ASR33 = is the character you have press shift for. : is unshifted.
Re:Why Does “=” Mean Assignment? by kps on Wednesday April 11, 2018 @10:39AM (#16811493)
Many early video terminals and microcomputers had similar layouts, because they were easy to implement. https://en.wikipedia.org/wiki/Bit-paired_keyboard
Re:Why Does “=” Mean Assignment? by roywiggins on Tuesday April 10, 2018 @06:46PM (#16806306)
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?
Re:Why Does “=” Mean Assignment? by 80386 on Wednesday April 11, 2018 @02:52AM (#16808674)
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? by dragonwriter on Tuesday April 10, 2018 @04:54PM (#16805284)
> "=" 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? by raverbashing on Tuesday April 10, 2018 @05:09PM (#16805452)
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 simpler/shorter one.

Re:Why Does “=” Mean Assignment? by boomlinde on Wednesday April 11, 2018 @03:58AM (#16808955)
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.
Re:Why Does “=” Mean Assignment? by kbp on Tuesday April 10, 2018 @06:03PM (#16805950)
> And most BASICs, though some (most?) required the keyword LET to introduce an assignment, as well.

LET was virtually always optional; an expression by itself on a line (like 'X <> 10') is a syntax error anyway, so removing LET doesn't introduce any ambiguity.

Re:Why Does “=” Mean Assignment? by Certhas on Tuesday April 10, 2018 @04:04PM (#16804775)
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.

Re:Why Does “=” Mean Assignment? by AnimalMuppet on Tuesday April 10, 2018 @04:12PM (#16804850)
And I dispute the "pretty much everybody used" part. In fact, I think the article contradicts that opinion. Algol used it, and so did Pascal. But Pascal was only a year old [Edit: at the time the choice was made for C] - it [Pascal] hadn't set the world on fire yet (to the degree that ever did). That leaves Algol using ":=", and FORTRAN, COBOL, and Lisp not using it. That's not "pretty much everybody used".
Re:Why Does “=” Mean Assignment? by hwayne on Tuesday April 10, 2018 @04:26PM (#16804976)
Yeah, it's probably more accurate to say that "everybody from the Algol line used := for assignment", with C being the first language of that line to stop.
Re:Why Does “=” Mean Assignment? by kps on Tuesday April 10, 2018 @05:43PM (#16805774)
> From the article:

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

Re:Why Does “=” Mean Assignment? by kps on Tuesday April 10, 2018 @10:43PM (#16807631)
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? by frou_dh on Wednesday April 11, 2018 @02:15AM (#16808504)
> Because K&R had terrible keyboards

There's no K in Thompson & Ritchie.

Kernighan seems to get inserted all over the place regarding Thompson's work. It's a bit disrespectful to the legend himself.

Re:Why Does “=” Mean Assignment? by z3t4 on Wednesday April 11, 2018 @02:02AM (#16808439)
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.
Re:Why Does “=” Mean Assignment? by DonaldPShimoda on Wednesday April 11, 2018 @02:40AM (#16808615)
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? by z3t4 on Wednesday April 11, 2018 @02:19PM (#16813880)
Chefs rather use a sharp knife then a blunt one, even if they cut themselves from time to time. If safety is a priority, there are special designed languages like Ada that use :=
Re:Why Does “=” Mean Assignment? by DonaldPShimoda on Monday April 16, 2018 @01:46PM (#16851050)
But... sharp knives are safer than blunt knives, specifically because they reduce the likelihood of being cut. That's why they're preferred.

I see your point, though. I was just bringing up an alternative consideration in the debate regarding equality.

Re:Why Does “=” Mean Assignment? by MichaelMoser123 on Wednesday April 11, 2018 @05:36AM (#16809431)
Or maybe because often used constructs are expressed by shorter symbols, because that makes it easier to write them down?
Re:Why Does “=” Mean Assignment? by walshemj on Tuesday April 10, 2018 @04:06PM (#16804797)
That I believe is only Algol the more widely used 1st gen languages FORTRAN and COBOL used = As did PL1/G
Re:Why Does “=” Mean Assignment? by ofrzeta on Tuesday April 10, 2018 @04:09PM (#16804832)
Pascal as well, and its descendents like Modula-2
Re:Why Does “=” Mean Assignment? by bad_user on Wednesday April 11, 2018 @01:12AM (#16808241)
The article is much more interesting than this comment.