Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel-eecis!news.mathworks.com!newsfeed.internetmci.com!info.ucla.edu!nnrp.info.ucla.edu!psgrain!qiclab.scn.rain.com!gemstone.com!servio!servio!aland
From: aland@servio.slc.com (Alan Darlington)
Subject: Re: Q For loops indices ... to: do:
Message-ID: <1996Jul22.184840.27723@gemstone.com>
Sender: news@gemstone.com (USENET News)
Nntp-Posting-Host: servio
Organization: GemStone Systems, Inc., Beaverton OR, USA
References: <Chameleon.960718164705.eli@pc032.spl.co.il>
Date: Mon, 22 Jul 1996 18:48:40 GMT
Lines: 62

Eli Hodos <eli@SPL.CO.IL> writes:
> Hi,
> 
> All vendors are straighting up to the ANSI standard.
> For example in VisualWorks the code was changed in VW 2.5 to accord with the
>  ANSI
> standard and differs from the code in VW 2.0 (or was it in a different class ?)
> 
> Eli.
> 
> ---------------Original Message---------------
> >1. It is customary that "aCollection remove: anItem ifAbsent: block"
> >returns the item that was removed, not the collection from which the
> >removal was done.
> >adhering to this tradition (one of many) will help save your sanity, and
> >preserve polymorphism among Collections.
> >--
> >Alan L. Lovejoy
> 
> I see that collections do this, but it does not make sense. If I say
> "aCollection add: something" why would I want "something" back?  I find this
> behavior rather non-intuitive & non-helpful, and I know others who feel the
> same.  Does it make sense for us to perpetuate this behavior, or should we be
> beginning to reverse the tide? Is polymorphism more important than sense?

Sense is in the eye of the beholder (or in this case, the code writer :-).
I have seen lots of the following type of code:

  set := aDictionary
      at: aKey
      ifAbsent:
        [aDictionary
          at: aKey
          put: Set new].

If #at:put: returned the dictionary, then set would not contain the
expected object.  You would instead have to write something like the
following:

  set := aDictionary
      at: aKey
      ifAbsent:
        [set := Set new.
        aDictionary
          at: aKey
          put: set.
        set].

(or use #ifTrue:ifFalse: with an #includesKey: test).  This kind of
code is much more awkward, lengthy, and harder to understand (IMHO).

Given that this is a fairly common type of code (at least I saw a
lot of it in Smalltalk-80 classes when I was at Xerox PARC Northwest),
you can see why the Smalltalk implementors wrote the code this way.

As always, of course, this is just opinion, and you can come up with
examples where returning the dictionary makes coding more convenient.

  Cheers,
  Alan
    (standard disclaimer)

