Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Why are "push", "pop", "shift" and "unshift" so named?

by davido (Cardinal)
on May 02, 2007 at 07:14 UTC ( #613129=note: print w/replies, xml ) Need Help??

in reply to Why are "push", "pop", "shift" and "unshift" so named?

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.


  • Comment on Re: Why are "push", "pop", "shift" and "unshift" so named?

Replies are listed 'Best First'.
Re^2: Why are "push", "pop", "shift" and "unshift" so named?
by jhourcle (Prior) on May 02, 2007 at 10:10 UTC

    Maybe I've just eaten in too many caffeterias in my life (I was a military brat, so that's quite possible), but from what I remember of caffeterias, some of them had the spring-loaded stacks for trays, not the plates.

    IF you're not in a self-service buffet, but an old style caffeteria -- you'd collect the tray and utensils yourself, but as you went down the line, you'd request specific items from the caffeteria workers. They'd put it on a plate, and hand you the plate of food. So the general public only saw the use of stacks on the trays, not necessarily the plates.

    These days, it's much rarer for the general public to see a caffeteria, and when you do, they've typically forgone the spring-loaded stack in exchange just a pile of trays. We do occassionally see stacks in use at self-service buffets. (some hotel restaurants, all-you-can-eat type places, etc), but it's more common in older establishments. Newer places just have a few piles of plates rather than the elegant spring-loaded stacks).


    So, anyway ... I'd hardly qualify wikipedia as authoritative in these sorts of things ... and the spring-loadedness, or even what is in the stack is less important than the fact that you can only easily get to the items in the reverse order they were placed on the stack.

    update: bah ... immediately after posting this, I realized that the spring-loadedness is necessary so that 'push' and 'pop' make sense in a polysemous way -- I still don't think _what_ is in the stack is necessarily significant.

    update2: I was in an IHOP yesterday, and saw a spring loaded stack, but it was for bowls. (so neither plates or trays)

      It's true that you don't see the spring-loaded tray or plate stacks as much, but it's an analogy that has stuck with us. We have a similar situation with "radio buttons" in graphical interfaces. The name is losing its meaning relative to actual radios over time, but the name is still here in a particular input type.

      As far as the contents of the stack: all analogies break down sooner or later. The stack of plates is just a starting point. This is Perl, so that stack could contain plates, trays, scalars, turkeys, or small cars.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://613129]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2019-12-13 00:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found