Writing the Inventory of a Method

If I were baking cookies, I would start by getting out all the ingredients -- butter, sugar, chocolate, eggs, more chocolate, baking powder, vanilla, more chocolate -- and arranging them on the counter. This way I can confirm that I have enough of everything I need, and it's all ready at hand when I need it. We'll do the same thing in writing a method: before we write any of the code for the method, we'll list (in comments) all the values we have available to use in writing that code. To remind us of what we can legitimately do with them, we'll write down the type of each one next to it.

For now, this is pretty simple: the only values we have available (other than literals) are the parameters of the method. So if we had the skeleton

public static int cube (int num)
   {
   }
adding an inventory would give us
public static int cube (int num)
   {
   // num         an int
   }

Similarly, if we had the skeleton

public static String howOld (String name, int age)
   {
   }
adding an inventory would produce
public static String howOld (String name, int age)
   {
   // name         a String
   // age          an integer
   }

So far, this is pretty simple, and for many of you it may seem like a waste of time. However, the inventories will get more interesting and more useful as the course goes on.


Last modified: Fri Jan 30 11:33:34 EST 2009
Stephen Bloch / sbloch@adelphi.edu