7
votes

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.

8

8 Answers

5
votes

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. :)

2
votes

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?

1
votes

I'll probably name it as push_back and pop_front.

0
votes

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.

0
votes

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.

0
votes

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 :)

0
votes

Pop / push sounds wrong as it suggests a stack data structure instead of a queue.

To add something new to the suggestions: my teachers always used in and out on the blackboard.

0
votes

I like entail and behead. Not for everyone though. Or "in with the new", "out with the old". And then for us Southwesterners there are berattle and defang. But my favorite is graphical. Right Arrow for in and then Right Arrow for out.