views:

284

answers:

6

The "queue", or FIFO, is one of the most common data structures, and have native implementations in many languages and frameworks. However, there seems to be little consensus as to how fundamental queue operations should be named. A survey of several popular languages show:

  • Python: put / get
  • C#, Qt : enqueue /dequeue
  • Ruby, C++ STD: push / pop
  • Java: add / remove

If one need to implement a queue (say, in some embedded platform that does not have a native queue implementation already), what naming convention would be best? Enqueue/dequeue seem to be the most explicit, but is wordy; put/get is succinct but does not provide any hint as to the FIFO nature of the operations; push/pop seems to be suggest stack operations instead of queue operations.

+1  A: 

I'll probably name it as push_back and pop_front.

Naveen
+1 Or top/bottom. Closer to memory terminology
Aiden Bell
A: 

Add/Remove sounds like the most logical one to use, especially if you are intending for it to possibly be read by person unfamiliar with the structure or the language (easier to understand).

Push/Pop would be next in my rankings because of personal preferences.

Put/Get comes next.

Enqueue/Dequeue is very last because I really hate the letter Q.

TheTXI
I just wouldn't want to type Enqueueueue all the time.
Aiden Bell
+1  A: 

I'm kind of a pedant, so I'd go with enqueue/dequeue.

Though add/next has a certain appeal.

Just to cloud the issue a little more, in Perl it's push/shift. :)

chaos
Why not just have bish() bosh() too :S TAOCP maybe the reference for dispute resolution?
Aiden Bell
+2  A: 

push/pop is plain wrong for a fifo as these are stack (first in last out) operations.

queue can refer to the object as well as an operation so is a bit overloaded and dequeue can cause confusion because it was commonly used to refer to a double ended queue.

put/get - short, obvious and generic (doesn't assume an implementation and can be used for all sorts of queues/lists/collections) - what's not to like?

Dipstick
+1 I agree with this one. push/pop is almost always associated with a stack, not a fifo
Andy White
A: 

Add/remove has the advantage that you can easily change from a queue to another data structure.

For example, storing states in a queue vs. a stack makes the difference between breadth-first and depth-first search.

starblue
A: 

I like enqueue and dequeue, but typing them sucks. So in my Queue structures (both C++ and Java), I named the functions enQ and deQ :)

JP McCool