Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

331–340 of 367 posts

Re: Why Does “=” Mean Assignment?

#331
post #40
post #10

Earlier quoted context omitted.

There’s also <-, most commonly seen in R but draws it’s heritage from the APL keyboard

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.

> 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?

#332
post #308

Earlier quoted context omitted.

> Once you know the purpose of the '=' how often do you make mistakes reading or writing code? A nontrivial proportion of people who start trying to learn to program never get past that point, so it's worth taking them into account. > at the end of the day, how often do you not know whether a particular variable is a string or an integer? Strawman. Types are not about the difference between a string and an integer, t…

>"Strawman. Types are not about the difference between a string and an integer, they're about the difference between a user id and an order id, or a non-empty list and a possibly-empty list, or..." Can you explain - how is the difference between a string and an integer different from the difference between a user id and an order id? You're calling the OPs comment a straw man but I'm not understanding how your example…

Many Ruby users don't realise that the type system can understand all these differences. How often do you not know whether a particular variable is a string or an integer? Not very often. How often do you not know whether a particular variable is a user id or an order id? Much more often. So if you think the only kind of difference a type system can tell you about is the difference between a string and an integer, you vastly underestimate the number of bugs that a type system could help you avoid.

Re: Why Does “=” Mean Assignment?

#333
post #307

Earlier quoted context omitted.

>"In other languages we might say we have assignment and destructuring ..." I'm not familiar with this term "destructuring." Can you elaborate on the concept? Might you have an example of a destructure operation and a language where its's used?

I could imagine by destructuring he means e.g. unapply in Scala: https://docs.scala-lang.org/tour/extractor-objects.html

Ah OK its a functional construct, this make sense. I have seen this in my brief exposure to Clojure. Thanks for the examples and links.

Re: Why Does “=” Mean Assignment?

#334
post #331
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.

> 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 (`…

That's a fantastic clarification, thanks for that!

Re: Why Does “=” Mean Assignment?

#335
post #323

As the article points out, the big first programming languages, FORTRAN, COBOL, LISP, and Algol each had their own way of doing variable assignment. FORTRAN used "=" and Algol used ":=" the other two languages used commands or functions to set or bind the values of variables. In the mid 60's, when I started programming, most programs had to be keypunched. (There was paper tape entry and Dartmouth's new timesharing sy…

> Naturally, symbols like "←" or "⇐" weren't available, but even the characters ":" and "

This explains why early ALGOL implementations (e.g. Burroughs, the only dwarf who went all in on the language) and dialects (ALGO, JOVIAL, MAD, NELIAC) actually used ‘=’ for assignment. This was perfectly legal according to the language definition, which distinguished between the ‘reference language’, which used ‘:=’, and its ‘hardware representation’, which could be anything. (Naturally there was no portability.)

Re: Why Does “=” Mean Assignment?

#336
post #128

Earlier quoted context omitted.

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.

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 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?

#337
post #154

Earlier quoted context omitted.

In the original Smalltalk implementation, the character corresponding to _ in ASCII was a left facing arrow, which Smalltalk used for assignment at the time.

I'm not following. The corresponding ASCII code for _ is 96 no? http://www.theasciicode.com.ar/extended-ascii-code/underline...

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?

#338
post #312

Earlier quoted context omitted.

>"In other languages we might say we have assignment and destructuring ..." I'm not familiar with this term "destructuring." Can you elaborate on the concept? Might you have an example of a destructure operation and a language where its's used?

https://clojure.org/guides/destructuring Basically it means that you can assign several variables at once, by asssigning a complex value to an aproprietly structured literal with variables as placeholders. In pseudojavascript, let's say you got this from some API: var someList = [1, 2, 3, 4]; var someMap = { name: "John Smith", age: 20, cars: [{ id: "AAA-1111", model: "Ford T"}, { id: "AAA-1112", model: "Mercedes Ben…

Javascript itself supports destructuing fine, here's some javascript straight from the firefox console:

    > let a = [1,2,3]
    undefined
    > [x,y,z] = a
    Array(3) [ 1, 2, 3 ]
    > x
    1
    > y
    2
    > z
    3

Re: Why Does “=” Mean Assignment?

#339
post #268

Earlier quoted context omitted.

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.

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?

#340
post #323

As the article points out, the big first programming languages, FORTRAN, COBOL, LISP, and Algol each had their own way of doing variable assignment. FORTRAN used "=" and Algol used ":=" the other two languages used commands or functions to set or bind the values of variables. In the mid 60's, when I started programming, most programs had to be keypunched. (There was paper tape entry and Dartmouth's new timesharing sy…

I feel like this is the best answer. People have to work with what they have. Much in the same way that SNES games look the way that do, even though the designers back then were just as smart and talented as the ones today. That’s simply what they could do with the medium at the time.

The limitations define the style. And then dogma perpetuates it, as the new generation continues to live with the results of once-great but now outdated thinking.

Post reply on HN