collectionDo: vs. collection do:
Hi, is there some best practice about collectionDo: versus collection do: ? I see many times the first used (e.g. String>>linesDo:); I see a benefit if there is no accessor to the collection, but more times than not there actually is.
From my perspective it further pollutes the protocol and as a user of such method I will never be sure what to actually use without looking at the implementation to see if there is any actual difference.
So is there some consensus on this? Thanks, Peter
Hi peter often xxx do: creates an intermediary collection while xxxDo: don't Stef Le 4/6/15 21:24, Peter Uhnák a écrit :
Hi,
is there some best practice about collectionDo: versus collection do: ?
I see many times the first used (e.g. String>>linesDo:); I see a benefit if there is no accessor to the collection, but more times than not there actually is. From my perspective it further pollutes the protocol and as a user of such method I will never be sure what to actually use without looking at the implementation to see if there is any actual difference.
So is there some consensus on this?
Thanks, Peter
Considering one of the tenants of OO is information-hiding**, then #linesDo: seems preferable. But I guess the problem is consistently implementing *all* the collection protocols. It might be interesting to have a kind-of Trait that applies to a single instance variable, that prefixes the Trait's method names with the ivar (or custom) name. ** But if the collection is returned to outside the object, its a bit of a mute point - and anyway anyone add an extension method that does this. cheers -ben On Fri, Jun 5, 2015 at 3:39 AM, stepharo <stepharo@free.fr> wrote:
Hi peter
often xxx do: creates an intermediary collection while xxxDo: don't
Stef
Le 4/6/15 21:24, Peter Uhnák a écrit :
Hi,
is there some best practice about collectionDo: versus collection do: ?
I see many times the first used (e.g. String>>linesDo:); I see a benefit if there is no accessor to the collection, but more times than not there actually is. From my perspective it further pollutes the protocol and as a user of such method I will never be sure what to actually use without looking at the implementation to see if there is any actual difference.
So is there some consensus on this?
Thanks, Peter
participants (3)
-
Ben Coman -
Peter Uhnák -
stepharo