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.
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.
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.
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.
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
. :)
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?
I'll probably name it as push_back
and pop_front
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With