Harsh J

Memoirs of a QWERTY Keyboard

Justice enough

leave a comment

About the immutability of variables once bounded in Erlang:

Single assignment is like algebra.

When I went to school, my math teacher said, “If there’s an X in several different parts in the same equation, then all the Xs mean the same thing.” That’s how we can solve equations: if we know that X+Y=10 and X-Y=2, then X will be 6 and Y will be 4 in both equations.

But when I learned my first programming language, we were shown stuff like this:
X = X + 1

Everyone protested, saying “you can’t do that!”. But the teacher said we were wrong, and we had to unlearn what we learned in math class. X isn’t a math variable: it’s like a pigeon hole/little box…

In Erlang, variables are just like they are in math. When you associate a value with a variable, you’re making an assertion – a statement of fact. This variable has that value. And that’s that.

Joe Armstrong, in his book Programming Erlang.

Written by Harsh

August 7th, 2010 at 11:08 pm

Posted in Computing Issues,Fun

Tagged with ,

Leave a Reply