On 25.10.2016, at 23:54, Chris Muller ma.chris.m@gmail.com wrote:
Hi Tobias and Eliot,
Folks there is NO BASIS at the level of Collection for assuming that do: [ : each | ^ false ] is faster than ^self size=0. In fact, the proper assumption is the opposite -- that #size is the optimized method, not #do:.
I don't understand on what _either_ performance-assumption is grounded.
Exactly. The original basis for making this change is groundless.
No Chris, I said I don't understand _both_ assumptions.
self size = 0 doesn't work for infinite collections.
What's an infinite collection,
For example, a generator… or a right-open interval?
[...]
ts or more the "clever" implementation is faster.
Then add Bag>>#isEmpty, don't change Collection>>#isEmpty, because it changes a 30-year old assumption about how #isEmpty works for every other kind of Collection.
Kent Beck gives this example for 'Simple Delegation':
Object subclass: #Vector instanceVariableNames: ‘elements’
Vector>>do: aBlock elements do: aBlock
It seems the #do:-based implementation is 'more correct' here.
I found no other recommendation in either Beck's or Thomas' style guides. To _me_ this suggests that what you perceive as 30-year-old-assumption is not as universal as '#do: should suffice'.
Best regards -Tobias