laziness, impatience, and hubris | |
PerlMonks |
Re: Why are "push", "pop", "shift" and "unshift" so named?by davido (Cardinal) |
on May 02, 2007 at 07:14 UTC ( [id://613129]=note: print w/replies, xml ) | Need Help?? |
I always thought that push and pop applied to a "cafeteria plates" metaphor, not trays. ;) Wikipedia seems to support this assertion. As the wikipedia article states, the cafeteria plates metaphor works because it conveys the notion of LIFO, as well as the notion that all but the top-most item are hidden from view in a traditional stack implementation as they are in a stack of cafeteria plates. If you don't like the plates metaphor; how about those vending machines with spiral dispenser? The last item loaded is the first one to pop off as the spiral turns to dispense the item. Or how about facial tissue; the top one is always the one that pops out next as you pull on it. Of course for that metaphor to really work you would have to assure that the box of tissue was loaded from the top. ;) Shift and unshift are perhaps a little more difficult. Since they occur at the zero end of a queue, the notion is that the entire queue has to shuffle up one for someone else to be placed in the zero position. And when one is taken from the zero position, everyone shifts down one spot. Think of a line of people. If the person at the front of the line passes through the threshold everyone else has to shift forward so that someone else can wait at the front of the line. Dave
In Section
Seekers of Perl Wisdom
|
|