18 ms·
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
by User23 9y ago
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.
- jghn 9y agoThere’s also <-, most commonly seen in R but draws it’s heritage from the APL keyboard
- nfoz 9y agoFun 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.
- bllguo 9y agoI 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!
- bachmeier 9y agoFWIW, 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.
- neuxenian 9y agoI'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.
- jghn 9y agoInteresting. 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
- bachmeier 9y agoI 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.
- jghn 9y agoI 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
- klmr 9y ago> 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.
- nfoz 9y agoThat's a fantastic clarification, thanks for that!
- blattimwind 9y agoCommon in Pre-Python pseudo code and algorithms.
- davvolun 9y agoAre you making an argument that Python has caused us all to start writing pseudo-code using `=` for assignment?
- chocolatebunny 9y agoI think he's making the argument that when we write "pseudo-code" these days we're just writing python
- kccqzy 9y agoWhen 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.
- kbp 9y agoIn the original Smalltalk implementation, the character corresponding to _ in ASCII was a left facing arrow, which Smalltalk used for assignment at the time.
- classichasclass 9y agoAnd now you know where the left-arrow on Commodore keyboards came from (same ASCII value): ASCII-1963, which became PETSCII instead of ASCII-1967.
- bogomipz 9y agoI'm not following. The corresponding ASCII code for _ is 96 no? http://www.theasciicode.com.ar/extended-ascii-code/underline-underscore-ascii-code-242.html http://www.theasciicode.com.ar/extended-ascii-code/underline...
- tom_mellior 9y ago"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 https://en.wikipedia.org/wiki/Smalltalk#Assignment
- kps 9y agoPre-1967 ASCII had slightly different printable characters and somewhat different control characters. See e.g. https://en.wikipedia.org/wiki/ASCII https://en.wikipedia.org/wiki/ASCII
- AnimalMuppet 9y agoTraditionally? I don't think there was a "tradition". ":=" was used in Algol. "=" was used in Fortran. COBOL didn't use either "=" or ":=".
- Certhas 9y agoFrom 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.
- AnimalMuppet 9y agoAnd 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".
- hwayne 9y agoYeah, 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.
- kps 9y ago> From the article: Articles, like desserts, aren't always right. I am sorely tempted to pull out Sammet's book tonight and start counting.
- kps 9y agoToo 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.
- cwzwarich 9y agoThe use of = for assignment goes back to Heinz Rutishauser's Suplerplan from 1951, and it was adopted by Fortran.
- 80386 9y agoRutishauser 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.)
- taejo 9y agoWhat are Strukturindizes?
- exceptione 9y agoThe translation would be structure indexes.
- taejo 9y agoYeah, 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.
- 80386 9y agoBauer 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.acm.org/10.1145/370000/361515/p678-bauer.pdf?key1=361515&key2=3342588511&coll=&dl=acm&CFID=15151515&CFTOKEN=6184618 https://web.archive.org/web/20090220012346/http://delivery.a... [2] http://www.cs.ru.nl/bachelorscripties/2010/Bram_Bruines___0213837___Plankalkul.pdf http://www.cs.ru.nl/bachelorscripties/2010/Bram_Bruines___02...
- deleted 9y ago[deleted]
- walshemj 9y agoThat I believe is only Algol the more widely used 1st gen languages FORTRAN and COBOL used = As did PL1/G
- ofrzeta 9y agoPascal as well, and its descendents like Modula-2
- kps 9y agoGranted 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.
- noonespecial 9y agoI 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.
- mturmon 9y agoThe shorthand I use for "becomes the same as" is "gets".
- ivyirwin 9y agoMy 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.
- noonespecial 9y agoI never liked the 'gets': "x gets 7" is fine but "x becomes the same as y" seems better than "x gets y"
- gowld 9y agothat's wrong, though. x becomes a copy of y, which is only transiently the same.
- dmichulke 9y agoWhat 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)
- Y_Y 9y agoDepends on the language, and the types of x and y. See e.g. python.
- 9y ago
- ddp 9y agoThe 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.
- tnecniv 9y agoTechnical 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.
- goatlover 9y ago> avoid confusion You’re kind of making the parent’s point.
- tnecniv 9y agoYes, 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.
- jjgreen 9y agoThe 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?
- bad_user 9y agoThe article is much more interesting than this comment.
- z3t4 9y agoI 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.
- DonaldPShimoda 9y agoYeah 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.
- z3t4 9y agoChefs 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 :=
- DonaldPShimoda 9y agoBut... 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.
- frou_dh 9y ago> 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.
- MichaelMoser123 9y agoOr maybe because often used constructs are expressed by shorter symbols, because that makes it easier to write them down?