4 ms·
>- A friend of mine, when showing him the statement 'x = x + 1' was confused; surely, x cannot also equal x+1. I think the best thing that my CS 101 prof did w
by krisgee 6y ago
>- A friend of mine, when showing him the statement 'x = x + 1' was confused; surely, x cannot also equal x+1.
I think the best thing that my CS 101 prof did was always refer to the assignment operator as "gets" so you'd say "eks gets eks plus one" out loud. It really helped divorce assignment and equality in my mind.
- fuball63 6y agoAnother helpful thing is how many programming languages have "assignment" and "comparison" operators. I remember TI basic has "=" for comparison, and "<-" for assignment, like, 'A<-5'. That one, to me made, the most sense. "Put the value of 5 in something called A."
- Delfino 6y agoiirc in TI-BASIC, assignment goes the other way so you could have "B + 5 -> A" which also helps seeing that the expression would be evaluated before storing (the button to input -> on the calc is STO, short for store).
- richard_todd 6y agoI’ve read that Dijkstra liked to say “becomes” for the same reason.
- Zuider 6y agoThere is an implicit and optional 'Let' statement preceding variable assignment BASIC, which was originally derived from FORTRAN (along with the practice of not using it.) It is less jarring to see: Let x = x + 1 because it could be read: we have a given value for x, now let us replace that value with x + 1.
- svusa 6y agoYou can also say "x is now equal to (the previous x)+1"
- DaveExeter 6y agox:=x+1 (Pascal)
- Delfino 6y agoSimilarly, I had a prof that referred to it as "becomes" which made great intuitive sense to me. "x becomes x plus one" makes me think of the variable transforming to the new value.