Nicolai, I think you are comparing apples and oranges here. AFAIK with:do: uses a second collection as first parameter and iterates over both of them. That's a completely different meaning of "with", imo. Let's not get started on the many ways in which with:do: is badly named ;-) I agree we can end this discussion as it is. I have two main arguments against renaming doWithIndex: one of which is that it would make Pharo just a little more incompatible with other dialects and one based on my guts about the name itself. This will not lead anywhere ;-) Joachim Am 16.03.15 um 13:41 schrieb Nicolai Hess:
---------- Forwarded message ---------- From: *Nicolai Hess* <nicolaihess@web.de <mailto:nicolaihess@web.de>> Date: 2015-03-16 13:40 GMT+01:00 Subject: Re: [Pharo-users] when iterating over a collection how to determine the current objects index To: "jtuchel@objektfabrik.de <mailto:jtuchel@objektfabrik.de>" <jtuchel@objektfabrik.de <mailto:jtuchel@objektfabrik.de>>
2015-03-16 12:19 GMT+01:00 jtuchel@objektfabrik.de <mailto:jtuchel@objektfabrik.de> <jtuchel@objektfabrik.de <mailto:jtuchel@objektfabrik.de>>:
Nicolai,
Am 16.03.15 um 11:59 schrieb Nicolai Hess:
2015-03-14 11:55 GMT+01:00 Sean P. DeNigris <sean@clipperadams.com <mailto:sean@clipperadams.com>>:
Marcus Denker-4 wrote > which version do we pick? We should pick one, rename the callers
As someone mentioned earlier in the thread, #doWithIndex: has the advantage of mirroring the argument order (although this still should be documented), and it's the one most people are probably most familiar with, so IMHO it makes sense to standardize on that.
I like withIndexDo: because code like
so how would you name the current #do: if you had the choice?
I still think this looks very logical:
#do: #do:separatedBy: #doWithIndex: #doWithSomeOtherSpecialty:andEvenMoreStuff:
And then there still ist the question if the order of the arguments should be changed:
today:
do: [:each| ] doWithIndex: [:each :index| ]
future:
do: [:each| ] withIndexDo: [:idx :each | ]
Do you really think that is better?
I think that if we move the withIndex part to the beginning of the message, it overstates the importance of the fact that we also need the index inside the iteration block.
aCollection withIndexDo: aBlock reads like "a collection with index" do
This would make sense if it was a Collection with an Index.
no, that is the point. A collection with no index: aCollection do:
A collection with no index, but iterator over it like it had one: aCollection withIndex do:
From the method comment: withIndexDo: elementAndIndexBlock "Just like with:do: except that the iteration index supplies the second argument to the block."
it looks like this method derives from :
SequenceableCollection>>#with: otherCollection do: twoArgBlock "Evaluate twoArgBlock with corresponding elements from this collection and otherCollection."
If there was an IndexedCollection class and maybe some message like asIndexedCollection or withIndex, which turns any collection into an IndexedCollection. Then the message might be a shortcut for "make thsi an indexed collection and iterate over it using its index" - comparable to Dictionary>>#keysAndValuesDo: - but please be aware that a Dictionary has keys and values by its very own nature. A Collection doesn't have an index (other than the fact that the elements are stored in some non-guarantueed order).
This may all sound quite picky, but I think this is plain wrong and you are about to introduce not only incompatible, but also misleading naming for methods that exist on all Smalltalk dialects.
I don't want to rename it, it is already there. I just said I like the one better than the other one. But it is not really important, I am fine with either or both. This was just my explanation why I would choose withIndexDo:
Joachim
----- Cheers, Sean -- View this message in context: http://forum.world.st/when-iterating-over-a-collection-how-to-determine-the-... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
-- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchelmailto:jtuchel@objektfabrik.de Fliederweg 1http://www.objektfabrik.de D-71640 Ludwigsburghttp://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1
-- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:jtuchel@objektfabrik.de Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1