#Computer Science

If you're not familiar with the idea of a reference, here's the basic concept. Suppose a variable in any programming language is a box with something in it.

Let's say box A is being stored by value. When I ask my computer, "Hey! What's in box A?" It looks inside the box and tells me the value. When I want to change the value of box A, my computer will change what is inside box A.

Now, let's say box B is being stored by reference. When I ask my computer, "Hey! What's in box B?" It says, "Well, box B is telling me to just tell you the value of box C. Box C has a value of foo, so box B has a value of foo, as well." When I want to change the value of box B, the computer goes "Well, box B just points at box C. So let me just change the value of box C instead."

The obvious implication is that you can have multiple pointers to one value. This is extremely useful once you start dealing with complex data structures. For instance, let's say I have some sort of a tree. I want to be able to traverse it in parent-child structure, but I also want to be able to access it by node name. I could create the tree in the form of parent-child structure as a deeply nested object, and then create an array of references pairing each node name with its reference in the tree.