Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by jbert (Priest)
on May 02, 2007 at 09:14 UTC ( [id://613141]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-16 22:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found