On 10/24/07, Todd Benson <caduceass / gmail.com> wrote:
> On 10/24/07, Todd Benson <caduceass / gmail.com> wrote:
> I'm surprised, though, that this thread has received so much
> attention.  I don't really have a problem with the terminology, or the
> behavior of the methods pop/push/shift/unshift.  In fact, the
> shift/unshift methods were two of many things that attracted me to
> Ruby.  I know they exist in other languages, but I haven't experienced
> the others in depth yet.

Well, I answered to this thread not because I had any problem with the
terminology, but to comment on the fact that pop/push is stack
semantics, and I would like also queue semantics. After thinking about
what David and I were discussing about how to make this happen, I'm
settled on the following if I ever want queue/stack semantics :

class Queue
   def initialize
      @buffer = []
   end

   def enqueue(element)
      @buffer.unshift(element)
   end

   def dequeue
      @buffer.pop
   end

   def empty?
      @buffer.empty?
   end
end

But, there's already a Queue implementation in ruby core, so I would
use that, although that class is aimed at synchronizing threads so I
might implement a simple queue like the above at some point if I need
simple queue semantics.
I would  corresponding class for Stack, with push/pop being delegated
to array's push and pop :-). Or just use an array if the fact of
having more methods than a stack is not a problem :-).

Jesus.