Variables

Variables are containers that have names and can contain values of a specific type.

I use a number of container in class for demonstrating this:

I write the type of the variable on the container itself with an indelible, fat, felt-tip pen. The name of the variable gets written on a Post-it and stuck on the variable for the life-time of the variable. Here is a picture of a variable A of type integer (ignore the lid, that is for parameters).

You can take a medium-sizen apple, write a "5" on it with the felt-tip pen, and put this value in the cup to demonstrate putting a value in a variable. If I put a second apple in, I will have to remove the first one - there is only room for one apple! On the back of an old CD you can write an 'A' and put it in the CD-Case - fits perfectly. But now try putting an apple in the CD-Case or a CD in the cup: it won't work, the types are not compatible. Of course, I can do a type conversion and break the CD into bits [I said use an *old* CD!] or make applesauce out of the apple, then I can put them in a container of the other type.

I once surveyed students 6 semesters after having seen these visualisations in the first semester of programming at the TFH. Many wrote, when asked to list any visualisations they could remember, "When you poured applesauce into the CD, that was something!". Note that I never actually poured applesauce, I only described doing it with an apple in my hand!

For more on variable use have a look at the Parameter list and the compound variables!


Debora Weber-Wulff <weberwu@htw-berlin.de>