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

Only 'push' and 'pop' come from the stack terminology. You 'pop' plates off the top (the rest of the plates 'pop' up when you do it I guess).

I would say 'shift' comes from shell scripting, where you 'shift' the arguments off of the list passed to the script. This is a fairly natural usage, and might also derive from assembly language, where a basic operation is to shift all the bits in a register one place left or right.

'unshift' is probably originates with perl and would have been named by analogy with 'shift' I think.

  • 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 bart (Canon) on May 02, 2007 at 13:37 UTC
    push and pop come from stack terminology, while shift comes from queues (to be combined with push).

    unshift is, like somebody else said, just the opposite of shift, like unget is the opposite of get. Not exactly proper English, but clear enough for the insiders — us.

    But technically, there's no reason why the array ends could not have been swapped. You get a just as fine stack if you just use unshift/shift as primitives instead of the usual push/pop, and, for queues, unshift/pop, instead of push/shift.