Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • 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.

like image 228
SytS Avatar asked May 29 '09 17:05

SytS


People also ask

How do you name a queue?

The syntax for queue names is as follows: The queue name must consist of one or more characters such as "A to Z", "a to z" or "0–9 ", “.”, “-”, “_”, and “/”. The total length is limited to 100 characters.

How do you name API models?

Use the same name or term for the same concept, including for concepts shared across APIs. Avoid name overloading. Use different names for different concepts. Avoid overly general names that are ambiguous within the context of the API and the larger ecosystem of Google APIs.

What naming convention should be used for method names?

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters.


3 Answers

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

like image 197
chaos Avatar answered Sep 30 '22 15:09

chaos


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?

like image 37
Dipstick Avatar answered Sep 30 '22 14:09

Dipstick


I'll probably name it as push_back and pop_front.

like image 1
Naveen Avatar answered Sep 30 '22 16:09

Naveen