Hacker News new | past | comments | ask | show | jobs | submit login

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




There 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.


Another 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."


iirc 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).


Similarly, 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.


I’ve read that Dijkstra liked to say “becomes” for the same reason.


You can also say "x is now equal to (the previous x)+1"


x:=x+1 (Pascal)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: