On Fri, Nov 1, 2013 at 7:54 PM, Kevin Gillette
<
extempor...@gmail.com> wrote:
> Regarding the actual implementation, I feel this is yet another area that
> can strongly benefit from a deep understanding of the zen of sort.Interface.
> Any non-interface slice can be used as a double-ended queue: precisely zero
> percent of the difficulty lies in storing elements, thus zero percent of a
> deque library should be concerned with storing elements itself. While it's
> possible for you to go the extra distance and use reflect to provide a
> concrete-typed veneer and prove that no type-mismatch panics occur, it's
> something that the compiler can't verify, and is less efficient by a large
> constant factor (often involving a dereference per access), and thus is
> comparatively undesirable.
I didn't know that sort.Interface was considered "Zen" now. There are
at least two ways of approaching all of these things: Either write the
specialized container and keep the elements general, or have someone
else write a more general container with specific elements and offer
certain specialized behavior (like sorting or heaps) on top of that.
The former leads to requirements on the elements (up to and including
zero requirements as is the case here) while the latter leads to a lot
of duplicated code (see the very sort module you reference with its
duplicated implementations of slices for basic types). I guess where
you see "Zen" I see a design tradeoff to be made in the least
convoluted way, and copying sort.Interface and friends for queues
doesn't seem worth it. Of course if you actually do it, please be sure
to let us know the outcome in terms of performance. I for my part am
happy to have at least beaten container/list.