Herby VojÄÃk wrote
Hello!
I've got this portion in my delegate:
requestPayload ifNotNil: [ uuidKeys do: [ :each | requestPayload at: each ifPresent: [ :s | requestPayload at: each put: (UUID fromString: s) ] ] ]. responsePayload := self towergame clientSync: requestPayload. responsePayload ifNotNil: [ uuidKeys do: [ :each | responsePayload at: each ifPresent: [ :uuid | responsePayload at: each put: uuid asString ] ] ].
Now I would gladly use something like Dictionary >> at:ifPresentTransform: aBlock. But it is not present, so I have two choices:
1. Add it as extension method, but then it may clash if someone else has similar idea.
I would make this choice. The extension is directly relevant to dictionary-ness, so an extenstion makes sense. But, I would go with a different name and a more familiar pattern: #transformAt:using: and #transformAt:using:ifAbsent:. You would use the latter, with an empty block for the #ifAbsent: keyword. The former, if you chose to implement it, would throw an /element not found/ exception if the key is not in the dictionary. I think it helps when the verb begins the behaviour name. Admittedly, there are numerous cases where the symmetry is more important, as with #at: and #at:put:. (But, probably because they are short.)
2. Add private helper TowergameDelegate >> dict:at:ifPresentTransform:, which is longer and needs additional self receiver.
Which is preferable?
Herby
-- View this message in context: http://forum.world.st/Stylistic-question-private-helper-vs-extension-method-... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.