[comp.lang.eiffel] Semantics of 'put' in list classes from the Data Structure Library

bertrand@eiffel.UUCP (Bertrand Meyer) (02/22/90)

    This is a further (I would like to say final, but it  is
no  use deluding oneself) answer to the question of routines
``put'', ``put_left'' and ``put_right''  in  the  chain  and
list  classes  from the Data Structure Library, as initially
raised by Bob Weiner and further addressed by myself,  Brian
Gilstrap,  Bob  Weiner  again,  Jos Warmer and Jim Gish (see
above references).

    I think I finally see what the problem is.  (One  should
not  despair  of  the  human race; just give people time and
they will understand.)

    In disagreement with Messrs. Weiner and Gish, I  do  not
think  the  name  ``put''  is improperly used in the classes
mentioned.  It  suffices  to  remember  that  the  universal
meaning of ``put'' in the Data Structure Library is ``put an
element in the appropriate cell''. The cell can be an  array
element,  a  stack  top,  a queue header, or, in the case at
hand, a list element at current cursor position.

    There is no reason why ``put'' should imply the idea  of
inserting  a  new  element.  In  ordinary language, the verb
sometimes connotes  insertion  (as  in  ``put  her  name  as
well'') and sometimes does not (``put her name, not mine, on
the third line'').

    In fact, the semantic distance (to  use  Mr.  Gilstrap's
term  in  <1127@swbatl.UUCP>)  seems smaller from ``put'' to
``place'' than it is to ``insert''. Both are listed  in  the
entry   for   ``put''  in  my  pocket-size  ``New  Webster's
Thesaurus'', along with ``assign, deposit, establish, imbed,
install, lay, locate, lodge, place, plant, settle''.

    For this reason, the current use of  ``put''  for  lists
seems beyond reproach.

    What is wrong, however (and this  is  really  the  valid
point  in  Mr.  Weiner's original message, which I missed at
the time), is the use of ``put_right'' and  ``put_left''  to
mean  ``insert to the right of the current cursor position''
and ``insert to  the  left''.  Clearly,  using  the  ``put''
prefix  here  is incompatible with the above interpretation.
More generally, there is a need for a verb,  different  from
``put'',  to  be  used  for  operations which add an element
rather than replacing an existing one. Since short names are
preferred   for   very   common  operations,  ``add''  seems
appropriate  for  this  purpose.   Then   ``put_left''   and
``put_right''    should    be    called   ``add_left''   and
``add_right'' (with the  old  names  kept  in  the  form  of
obsolete routines, of course).

    I would also  like  to  qualify  Mr.  Warmer's  comments
<5235@star.cs.vu.nl>:

> One of the first things students learn is that the name of
> a routine  should  provide  infomation on its semantics.
> This is very important.  Try to change  all  routine-names
> into  names  that suggest diferent semantics and you won't
> be able to read the code anymore.


    Yes. But then the second thing students should be taught
is  that  in  a  large  conceptual  structure (a programming
project, an operating system, a programming environment,  or
the  Eiffel  libraries) the consistency of the naming system
is just as important as  the  individual  adequacy  of  each
time.  The optimal naming system is a tradeoff between these
two goals. If we  had  not  come  to  that  realization  the
``put''  operation  for  stack classes would still be called
``push'', the ``item'' operation for arrays would  still  be
called  ``entry''  - and of course all this discussion would
never have occurred.


-- Bertrand Meyer
bertrand@eiffel.com