Traditionally := was used for assignment, which makes sense since it is an asymmetric symbol for an asymmetric operation.
Traditionally := was used for assignment, which makes sense since it is an asymmetric symbol for an asymmetric operation.
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.
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.)[1] https://web.archive.org/web/20090220012346/http://delivery.a...
[2] http://www.cs.ru.nl/bachelorscripties/2010/Bram_Bruines___02...
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.
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
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.
I spent some time as a package author, that’s where I found <<- to be the most useful
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.
http://www.theasciicode.com.ar/extended-ascii-code/underline...
You’re kind of making the parent’s point.
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.
let mutable x = 4 // x is equal to 4
x <- 7 // x is equal to 7We 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.
"x gets 7" is fine but
"x becomes the same as y" seems better than "x gets y"
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)
> 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.
Articles, like desserts, aren't always right. I am sorely tempted to pull out Sammet's book tonight and start counting.
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.
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%BClSo, there really was a lot of languages out there, but := was fairly common because it was easy to parse and type.
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.
Rutishauser was, at least.
And most BASICs, though some (most?) required the keyword LET to introduce an assignment, as well.
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.
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.
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.
I see your point, though. I was just bringing up an alternative consideration in the debate regarding equality.