[squeak-dev] collect:thenDo: woes
Levente Uzonyi
leves at caesar.elte.hu
Wed Sep 11 14:46:12 UTC 2019
On Wed, 11 Sep 2019, Stéphane Rollandin wrote:
> Richard O'Keefe is making good points against the Squeak implementation
> of method #collect:thenDo: in the Pharo-users list:
I disagree.
His idea is that #collect:thenDo: ought to work differently, calling
Squeak's implementation "pointless", because it is what its name suggests:
#collect: followed by #do:. But there's a small twist: the collected
values are returned.
Then he brings up the red herring: examples where #collect: does something
a naive user would not expect, and where #collect:as: should be used. Then
blames it all on #collect:thenDo:.
Next, he shows how good those examples work in Pharo, with the new
implementation. Even though he forgets to point out that the new
implementation has different semantics (when your blocks have side
effects) and different return value (because it doesn't create an
intermediate collection to return), which can break your code[1].
In the summary, he writes that "[the Squeak definition] does not improve
readability. In fact, it REDUCES readability". I think having a fewer
parentheses can help with legibility.
He also writes "[the Squeak definition] is useless with most collection
classes.". I somewhat agree with this. I wouldn't use it in a method, but
it sometimes comes handy in a workspace script (just like #in:).
Finally, "[the Squeak definition] does nothing to improve performance
but just adds overhead.". I suppose no one wanted to improve performance
with that method.
>
> https://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/2019-September/044204.html
>
> I vote for the removal of this confusing method.
I'm not against deprecating it, because every now and then it brings up a
similar discussion, but then all other methods of the same kind (*:then*:)
must go as well from the collections.
Levente
[1] http://forum.world.st/Bad-reimplementation-of-Collection-gt-gt-collect-thenDo-in-Pharo-3-0-td4760774.html
>
> Stef
>
>
More information about the Squeak-dev
mailing list
|