You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently both dequeue and dequeueEnd methods return null if the queue is empty when they're called. This is a fairly unobtrusive implementation but does have two fairly significant drawbacks:
Instances will indefinitely return null whilst their queue is empty. This means that users must manually check to see if their latest dequeue/dequeueEnd call emptied the queue.
If the user adds null to the queue they have no way of knowing if the null that dequeue/dequeueEnd returns is an inserted value or the "queue is empty" value. Again, they must manually check if the queue is empty instead.
Proposal
A potential solution is to instead throw an error when dequeue/dequeueEnd are called when the queue is empty. This solves both above issues. The instance will inform the user when the queue is empty, since they will have to deal with an error, and null values returned can safely be assumed to be values in the queue.
constqueue=newQewe();try{constvalue=queue.dequeue();// do something with value}catch{// queue is empty, do something else}
Drawbacks
This behavior change does come with a little overhead. Users would have to handle errors, likely with a try/catch block, or their application would crash.
Alternative
An alternative is to suggest users check if the queue is empty before they call dequeue/dequeueEnd.
constqueue=newQewe();if(queue.isEmpty===false){constvalue=queue.dequeue();// do something with value}else{// queue is empty, do something else}
The text was updated successfully, but these errors were encountered:
Currently both
dequeue
anddequeueEnd
methods returnnull
if the queue is empty when they're called. This is a fairly unobtrusive implementation but does have two fairly significant drawbacks:null
whilst their queue is empty. This means that users must manually check to see if their latestdequeue
/dequeueEnd
call emptied the queue.null
to the queue they have no way of knowing if thenull
thatdequeue
/dequeueEnd
returns is an inserted value or the "queue is empty" value. Again, they must manually check if the queue is empty instead.Proposal
A potential solution is to instead throw an error when
dequeue
/dequeueEnd
are called when the queue is empty. This solves both above issues. The instance will inform the user when the queue is empty, since they will have to deal with an error, andnull
values returned can safely be assumed to be values in the queue.Drawbacks
This behavior change does come with a little overhead. Users would have to handle errors, likely with a try/catch block, or their application would crash.
Alternative
An alternative is to suggest users check if the queue is empty before they call
dequeue
/dequeueEnd
.The text was updated successfully, but these errors were encountered: