Digging a bit further, the change from the pointless implementation to
the current implementation was made between Pharo 2.0 and Pharo 3.0
and the current definition was introduced into ST/X some time between
2010 and 2012, which is about the same time as Pharo.
{collect,select,reject}:thenDo: were added to my library on
2004.09.14, exactly a day after the version now in Squeak.  Which
leads me to believe that I picked the method up from a previous
version of Squeak and that some of the Squeak version history has
been lost.

By the way, it's not just Sets where the current Squeak definition is
a pain in the posterior.  Consider the following example.

  |o|
  o := OrderedCollection new.
  #[3 1 4 1 5 9]
    collect: [:byte | byte asFloat]
    thenDo: [:float | o addLast: float].
  Transcript print: o; cr.

This works fine in Pharo, in Smalltalk/X, and in my library.
It raises an exception in Squeak.
Or try

   #[3 1 4 1 5 9]
     collect: [:byte | byte odd ifTrue: [byte printString]
                                ifFalse: [byte]]
     thenSelect: [:each | each isNumber]

In Pharo and my library, it straightforwardly answers #[4].
In Squeak, it raises an exception.

So that's sets where the current Squeak definition can give you
trouble, and ByteArrays, and we are not done yet!  Pretty much
anything other than an Array or an OrderedCollection is going to
get you in trouble in Squeak.  Just think of the fun you can
have with SortedCollection.  Ooh, the list goes on and on.

So, the Squeak definition
* does not improve readability.
  In fact, it REDUCES readability because the human reader stops
  to ask "why is this portmanteau method used rather than the
  obvious code" and several minutes later discovers that there
  is NO reason.
* is useless with most collection classes.
* does nothing to improve performance but just adds overhead.

Are we done yet?



On Tue, 10 Sep 2019 at 01:27, David T. Lewis <le...@mail.msen.com> wrote:

> On Mon, Sep 09, 2019 at 05:46:48PM +1200, Richard O'Keefe wrote:
> >
> > (3) Oddly enough, the reason that #collect:thenDo: exists in my
> >     library is that I copied it from Squeak, at a time when it had
> >     the same definition as Pharo and ST/X.  Had I known of the change
> >     in Squeak I would have bitterly opposed it.  The comment in the
> >     current Squeak code, that it is for readability, is 100% the
> >     reverse of the truth.  Using the version with parentheses is WAY
> >     clearer than using the portmanteau method.  Sigh.  I see they
> >     broke #collect:thenSelect: in the same way.
> >
>
> In Squeak, collect:thenDo: is implemented only in Collection.
> The method stamp is dgd 9/13/2004 23:42, which hardly qualifies as
> a recent change. And the method stamp for collect:thenSelect: is
> sma 5/12/2000.
>
> Dave
>
>
>

Reply via email to