Programming metaphors

Posted Saturday, April 1, 2006

Filed under: ,

Programming is relatively easy, good programming is harder (as the saying goes).
The following ideas are useful metaphors to relate to when trying to get a mental picture of some concepts.

First, variables.
As found in this online version of "how to design programs", variables can compare to widely known concepts.
A disc area equals to Pi * r^2. R in this expression can contain any number corresponding to a disc radius. R is a variable.

Next come arrays.
Arrays are a collection of items, structured into a table. But these "tables" can have more dimensions than the ones we are used to eating at. Apart from this, these special tables can additionnally hold information about the type of data inside their rows and columns, and make it easy to point to this data using the column and row number (or name).
The calendar metaphor used to explain multidimensionnal arrays in "Arrays in WikiBooks" is enlightening.

On declaring variables I came up with the mailbox metaphor the other day. Should it help anyone, I put it up here as well. Saving data to a variable is like sending someone something: you need to know that person's address beforehand, and the post office has to know that person's address too. Defining and instantiating a variable is like registering the sendee's address with the post office, and once done you can start sending parcels and letters (storing data) to that person.

Hope this helps...

Comments disabled because of spammers.

No comments yet

Technorati Profile