Nicolai,
Am 16.03.15 um 11:59 schrieb Nicolai Hess:
so how would you name the current #do: if you had the choice?
2015-03-14 11:55 GMT+01:00 Sean P. DeNigris <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
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.
This would make sense if it was a Collection with an Index.aCollection withIndexDo: aBlock
reads like
"a collection with index"�� do
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.
Joachim
��
-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/when-iterating-over-a-collection-how-to-determine-the-current-objects-index-tp4810920p4811848.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
-- ----------------------------------------------------------------------- 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