SytS
SytS

Reputation: 1579

Terminology/naming convention for queue operations/APIs?

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:

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.

Upvotes: 7

Views: 4906

Answers (8)

user23713
user23713

Reputation: 1

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.

Upvotes: 0

Croo
Croo

Reputation: 1371

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.

Upvotes: 0

JP McCool
JP McCool

Reputation:

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

Upvotes: 0

starblue
starblue

Reputation: 56772

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.

Upvotes: 0

Dipstick
Dipstick

Reputation: 10129

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?

Upvotes: 2

chaos
chaos

Reputation: 124297

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

Upvotes: 5

TheTXI
TheTXI

Reputation: 37895

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.

Upvotes: 0

Naveen
Naveen

Reputation: 73443

I'll probably name it as push_back and pop_front.

Upvotes: 1

Related Questions