Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by jbert (Priest)
on May 02, 2007 at 09:14 UTC ( #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
Node Status?
node history
Node Type: note [id://613141]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2019-11-19 02:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (93 votes). Check out past polls.

    Notices?