linked lists and a matter of terminology

Robert P. J. Day rpjday at mindspring.com
Fri May 19 14:34:49 UTC 2006


On Fri, 19 May 2006, Michael S. Zick wrote:

> On Fri May 19 2006 09:08, Robert P. J. Day wrote:
> >
> >   and while we're on the subject of linked lists, can i make a
> > suggestion to rename those function primitives?  i've never been happy
> > with primitives like "add_to" and "add_to_end" since they're sort of
> > vague and wishy-washy.  i think it would be far more meaningful to use
> > "prepend" and "append", which have *independently* unambiguous
> > meanings.
> >
> >   (as an aside, i've always been thoroughly disgusted with perl's
> > decision to name the four related operators "push", "pop", "shift" and
> > "unshift".  what hideous and inconsistent choices.  grrrrrr ...)
> >
> >   in any event, i think "prepend" and "append" are more
> > clearly-defined since they obviously denote an underlying ordering.
> >
> >   thoughts?
> >
>
> "prepend" and "append" imply a known order context.

yup, they sure do.

> That is, the location they refer to depends on if the list is being
> used FIFO or FILO.

i disagree.  "prepend" has always meant "at the front," while "append"
has always meant "at the end."  if you start getting into distinctions
of FIFO versus FILO, then you should be using a "stack," not a "list."
the standard operations on the abstract data type "list" have been
around for a long time.  there's no reason not to use them here.

> And if you are using the list to reverse the order become meaningless.

if you "reverse" a list, then it's a new list with a different order.
no problem there.  the last shall be first, the first shall be last.
:-)

> But I agree, the current names are ugly (no comment on the 2,000lb
> camel).

> How about:
> add_head, add_tail, rmv_head, rmv_tail?

well, personally, i'd still go with "append" and "prepend" but a more
salient question is, what operations *should* be supported for the
abstract data type you're defining?

if you want to define a structure that supports LIFO behaviour, you
should perhaps call it a "stack."  if you want FIFO, well, that's a
"queue."  all of these things have a long and well-defined history.
i'm just sayin'.

rday




More information about the busybox mailing list