Hello, I am working on a new collection and this question caught my interest. Between doWithIndex: or withIndexDo:, which do you find more logical and why? Oleks
I don't like either of those and use #keysAndValuesDo: as it is polymorphic with other collection classes. That said, I'd prefer #withIndexDo: [:each :index | ... ] because it preserves the #with:do: structure. e.g. #($a $b $c) with: (1 2 3) do: [:char :number | ... ] Regards, Esteban A. Maringolo El mar., 12 mar. 2019 a las 12:27, Oleksandr Zaytsev (<olk.zaytsev@gmail.com>) escribió:
Hello,
I am working on a new collection and this question caught my interest. Between doWithIndex: or withIndexDo:, which do you find more logical and why?
Oleks
#doWithIndex: for me. Both because it's the selector I'm used to from other dialects, and the parameter order [:element :index | ] makes more sense to me. Cheers, Henry -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Yes - I like the prefix doXXX too, as I often think first of do: for normal iteration, with suffixed selectors for other variations.
On 12 Mar 2019, at 16:54, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
#doWithIndex: for me.
Both because it's the selector I'm used to from other dialects, and the parameter order [:element :index | ] makes more sense to me.
Cheers, Henry
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Neither. No two ways about it. #keysAndValuesDo: However, seq with: seq keys do: aBlock and seq withIndexDo: aBlock do the same thing, so #withIndexDo: makes some sense. This is not my opinion alone. I'm typing this on a machine that has Squeak but not Pharo. In Squeak we find doWithIndex: elementAndIndexBlock "Use the new version with consistent naming" ^ self withIndexDo: elementAndIndexBlock "New" means since 1997. On Wed, 13 Mar 2019 at 04:27, Oleksandr Zaytsev <olk.zaytsev@gmail.com> wrote:
Hello,
I am working on a new collection and this question caught my interest. Between doWithIndex: or withIndexDo:, which do you find more logical and why?
Oleks
participants (5)
-
Esteban Maringolo -
Henrik Sperre Johansen -
Oleksandr Zaytsev -
Richard O'Keefe -
Tim Mackinnon