Parameter Passing with Frisbees

Originally due to Michael Clancy

 

Back in the days in which we taught using Pascal, it was necessary to distinguish between parammeter passing by "value" and by "reference". Michael Clancy at Berkeley developed a nice illustration using Frisbees, which was a very popular toy among college students at the time.

 

Pass by Reference

  1. Take one Frisbee
  2. The "sender" attaches a piece of paper to it with tape, labels it with the name of a variable, and writes a value for the value on the card.
    At the sender.
  3. The sender passes the Frisbee to someone else ("receiver"), who has access to the value and may change it. When done, the receiver sends the Frisbee back to the original sender.
    As received by the receiver.
    Modified by the receiver.
  4. The value has been changed for the original sender.
    Back at the sender.

Pass by Value

  1. Take one Frisbee as before.
  2. The "sender" attaches a piece of paper to it with tape, labels it with the name of a variable, and writes a value for the value on the card. (As before).
    At the sender.
  3. The sender then places the Frisbee into a clear plastic bag.
    At the sender.
  4. And then attaches another piece of paper with a copy of the value seen through the bag.
    At the sender.
  5. The Frisbee and bag combination is now passed to the receiver who sees the value and may modify it.
    Changed by the receiver.
  6. When finished, the receiver passes the Frisbee back to the original sender--without the bag.
    Back at the sender.
    There is no change seen by the sender.

Note, however, that while this does illustrate these two parameter passing mechanisms, it is less satisfactory for use in a language like Java which has only pass by value. In Java, objects are NOT passed by reference. Instead, a reference to an object is passed by value. That reference may be used to access the object in any way that the object permits, but the reference itself may not be changed from the viewpoint of the sender. If the receiver changes the reference, then a different object may be referenced within the function, however.

 

Last Updated: July 22, 2000